-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add an option to specify which Python to use? #46
Comments
Update: It seems that nimpy works with python's/conda's virtualenvs. But if the base/root env is activated, then nimpy doesn't use that one, and uses system's Python. EDIT: No, it is more crazy than that (at least on my end): |
Nimpy needs to find python library if loaded not from within python, and here's how it does that: https://github.com/yglukhov/nimpy/blob/master/nimpy.nim#L729-L744. I could add an explicit initialization function to be called by the user, but maybe it would be possible to adjust the "automagic" search to suite your needs? |
Here it is once again the situation I have faced, this time explained in more detail, just to make sure we are on the same page. I have system's python and conda's python:
As you can see, when I run Conda Python is the Python I work with, and it has all the libraries I need and use, e.g. numpy, matplotlib, etc. If I try to run Python from Nim using Nimpy, Nimpy calls system's Python (with no extra libraries installed) so I cannot use Nimpy with numpy, matplotlib, etc. import nimpy
let pysys = pyImport("sys")
echo pysys.version
let np = pyImport("numpy")
let n = np.array([1, 3, 2, 5, 6, 4])
echo "mean ", n.mean()
But now comes the funny/tricky/strange part. If I create a virtual env with Python 3.7 (the same version as system's Python) and there I install the libraries I want to use, what Nimpy does is: it uses system's Python with the libraries from virtual env!
Running the same file from above gives now:
Notice the Python version (it is system's Python), and there was no problems with importing and using numpy. |
I would rather keep the 'automagic' as the default behaviour (no explicit initialization), as it makes nimpy very elegant to show (off :)) and use. But I'm not sure how to deal with the behaviour explained in the previous comment. If there is a possibility to add an override of the default behaviour by specifying custom Python path, I think that might solve the issue. |
I've never used conda and don't know how it works, so bear with me. Also let me emphasize it once again: running python from nim involves searching for
|
|
Huh, completely different, ok. What about the |
In all three cases it is the same:
|
Ok, so it seems conda doesn't change the dylibs. And one mystery remains as to how py37env is picked up by nimpy. I'm out of ideas for now. As a quick and dirty workaround, you can just add the needed paths to let sp = pyImport("sys").path
for p in ["/home/miran/miniconda3/lib/python3.6", "/home/miran/miniconda3/lib/python3.6/lib-dynload", "/home/miran/miniconda3/lib/python3.6/site-packages"]:
sp.append(p) |
Thanks for your help nonetheless! |
Added |
How to use it to set the path? thanks |
workaround: use |
I've tried calling Python from Nim (as shown in the Readme), just to realize it calls system's python, not the version I use for developing (installed via conda) which has all the libraries I usually use (e.g. numpy, matplotlib, etc.)
Could there be a way to specify which Python to use?
Maybe something like this?
The text was updated successfully, but these errors were encountered: