Skip to content

Importing python modules failed from the specified python #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shayandavoodii opened this issue Dec 3, 2022 · 4 comments
Closed

Importing python modules failed from the specified python #252

shayandavoodii opened this issue Dec 3, 2022 · 4 comments

Comments

@shayandavoodii
Copy link

shayandavoodii commented Dec 3, 2022

Today I installed the latest version of PythonCall.jl (v0.9.10) package and started with:

julia> using PythonCall

julia> ENV["JULIA_CONDAPKG_BACKEND"] = "Null"
"Null"

julia> ENV["JULIA_PYTHONCALL_EXE"] = raw"C:\Users\Shayan\AppData\Local\Programs\Python\Python310\python.exe"
"C:\\Users\\Shayan\\AppData\\Local\\Programs\\Python\\Python310\\python.exe"

Then I closed the Julia session and started a new one to continue. Then I failed to import the numpy package via pyimport:

julia> using PythonCall

julia> pyimport("numpy")
ERROR: Python: ModuleNotFoundError: No module named 'numpy'
Python stacktrace: none
Stacktrace:
 [1] pythrow()
   @ PythonCall C:\Users\Shayan\.julia\packages\PythonCall\3GRYN\src\err.jl:94
 [2] errcheck
   @ C:\Users\Shayan\.julia\packages\PythonCall\3GRYN\src\err.jl:10 [inlined]
 [3] pyimport(m::String)
   @ PythonCall C:\Users\Shayan\.julia\packages\PythonCall\3GRYN\src\concrete\import.jl:11
 [4] top-level scope
   @ REPL[2]:1

Also, I tried setting the path to the directory rather than the executable Python:

julia> ENV["JULIA_PYTHONCALL_EXE"] = raw"C:\Users\Shayan\AppData\Local\Programs\Python\Python310"
"C:\\Users\\Shayan\\AppData\\Local\\Programs\\Python\\Python310"

But, still, I couldn't import numpy. Note that I made sure that the numpy is installed in the specified environment:

C:\Users\Shayan>pip list numpynumpy              1.23.5
@cjdoris
Copy link
Collaborator

cjdoris commented Dec 3, 2022

You need to set those env vars before you import PythonCall, and they need to be set every time - so if you restart Julia you need to set them again.

It's usual to set these in your Julia startup file or your shell startup file if you're coming from bash/zsh/etc.

@shayandavoodii
Copy link
Author

@cjdoris

need to set those env vars before you import PythonCall...

Both .../Python310 and .../Python310/python.exe? I guess one of these would be enough(?).

@shayandavoodii
Copy link
Author

shayandavoodii commented Dec 3, 2022

You need to set those env vars before you import PythonCall, and they need to be set every time - so if you restart Julia you need to set them again.

It's usual to set these in your Julia startup file or your shell startup file if you're coming from bash/zsh/etc.

Setting the following lines into the startup.jl file get the job done:

ENV["JULIA_CONDAPKG_BACKEND"] = "Null"
ENV["JULIA_PYTHONCALL_EXE"] = raw"C:\Users\Shayan\AppData\Local\Programs\Python\Python310\python.exe"
julia> using PythonCall

julia> ts = pyimport("transformers")
Python _LazyModule: <module 'transformers' from 'C:\\Users\\Shayan\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\transformers\\__init__.py'>

Thanks. Please note to mention this precisely in the documentation as well.

@cjdoris
Copy link
Collaborator

cjdoris commented Dec 3, 2022

Thanks. Please note to mention this precisely in the documentation as well.

You're welcome. Will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants