Skip to content
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

Python 3 not found on Mac OS #144

Closed
jfilby opened this issue Apr 14, 2020 · 8 comments
Closed

Python 3 not found on Mac OS #144

jfilby opened this issue Apr 14, 2020 · 8 comments

Comments

@jfilby
Copy link

jfilby commented Apr 14, 2020

When I try import a non-standard module I get an error. However when I import os it works fine.

When I run the following code:

let pysys = pyImport("sys")
echo pysys.version

It looks like nimpy is using Python 2 instead of Python 3. How can I point it to Python 3? I'm using a virtual environment to setup Python 3.

I found a similar issue: #46

@jfilby jfilby changed the title Package not found (part of Python virtual environment) Package not found for pattern.en Apr 14, 2020
@yglukhov
Copy link
Owner

You can use pyInitLibPath("/path/to/python.so") for that.

@jfilby
Copy link
Author

jfilby commented Apr 14, 2020

Is pyInitLibPath() new? I installed Nimpy using nimble but when I try to compile I get:
Error: undeclared identifier: 'pyInitLibPath'

Also, do you know the actual name of the library? I don't have a python.so file on my system (Mac OS).

@jfilby jfilby changed the title Package not found for pattern.en Python 3 not found on Mac OS Apr 15, 2020
@jfilby jfilby closed this as completed Apr 15, 2020
@jfilby
Copy link
Author

jfilby commented Apr 15, 2020

It worked with the latest code, thanks, I just pointed pyInitLibPath to the python 3 binary in my virtual env.

@drewbitt
Copy link

drewbitt commented Apr 25, 2020

@yglukhov why is this necessary for MacOS but not for windows? Code runs fine on Windows without specifying the path but doesn't on MacOS for me as well.

python -c 'import sys; print(sys.path)'
['', '/Users/drewbitt/.pyenv/versions/3.8.2/lib/python38.zip', '/Users/drewbitt/.pyenv/versions/3.8.2/lib/python3.8', '/Users/drewbitt/.pyenv/versions/3.8.2/lib/python3.8/lib-dynload', '/Users/drewbitt/.pyenv/versions/3.8.2/lib/python3.8/site-packages']

In nimpy:

['/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Users/drewbitt/Documents/Github/wn-reading-list-backend/src/util']

which is the system python

There is no libpython*.so*

@drewbitt
Copy link

It looks like you load the first libpython*dylib you find. Can we get the ability to specify what version we want then?

@drewbitt
Copy link

Actually, that wouldn't help here since it is completely not finding any python3 dylibs.

@singularperturbation
Copy link

If you're using pyenv on Mac OS, make sure that you have PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install <VERSION> to get it built with a dynamic library, otherwise I don't think that this will work (because it will only have a static library to load).

(found this from JuliaPy/PyCall.jl#122)

@timotheecour
Copy link
Contributor

timotheecour commented Sep 30, 2020

workaround: use find_libpython to find the libpython shared library reliably; see #171

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

5 participants