JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

Failed to load PyCall on M1 Mac #911

Closed dk1013 closed 3 years ago

dk1013 commented 3 years ago

I have installed Julia using official installer on a M1 Mac and installed PyCall with below command: Pkg.add(PackageSpec(name="PyCall", rev="master")) When I tried to import PyCall, I got the error: "ImportError: No module named site", and the terminal just died. I'm not using a custom path for Python. Any idea?

stevengj commented 3 years ago

What is the output of pkg> build -v PyCall?

dk1013 commented 3 years ago

Hi @stevengj , sorry for the late reply. Following your hint, I managed to rebuild it and got it work. Initially, I got this output:

(@v1.6) pkg> build -v PyCall Building Conda ─→ ~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/299304989a5e6473d985212c28928899c74e9421/build.log Building PyCall → ~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/169bb8ea6b1b143c5cf57df6d34d022a7b60c6db/build.log [ Info: PyCall is using /Users/.../miniforge3/envs/.../bin/python (Python 3.9.0) at /Users/.../miniforge3/envs/.../bin/python, libpython = /System/Library/Frameworks/Python.framework/Versions/2.7/Python [ Info: /Users/.../.julia/packages/PyCall/BD546/deps/deps.jl has not changed [ Info: /Users/.../.julia/prefs/PyCall has not changed

So it seems it's because it's linked to my own Python. After resetting ENV["PYTHON"] and rebuild, now it works. The output is:

(@v1.6) pkg> build -v PyCall Building Conda ─→ ~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/299304989a5e6473d985212c28928899c74e9421/build.log Building PyCall → ~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/169bb8ea6b1b143c5cf57df6d34d022a7b60c6db/build.log ┌ Info: Using the Python distribution in the Conda package by default. └ To use a different Python version, set ENV["PYTHON"]="pythoncommand" and re-run Pkg.build("PyCall"). [ Info: Running conda install -y numpy in root environment Collecting package metadata (current_repodata.json): done Solving environment: done # All requested packages already installed. [ Info: PyCall is using /Users/.../.julia/conda/3/bin/python (Python 3.8.5) at /Users/.../.julia/conda/3/bin/python, libpython = /Users/.../.julia/conda/3/lib/libpython3.8.dylib [ Info: /Users/.../.julia/packages/PyCall/BD546/deps/deps.jl has not changed [ Info: /Users/.../.julia/prefs/PyCall has not changed

Now the issue can be closed. Thank you!