Jupyter uses wrong version of numpy - python

I am trying to import pandas in a Jupyter notebook and having trouble because it's using an old version of numpy. I believe I've traced the issue to the fact that I have two versions installed:
Version 1.8.0rcl is in:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Version 1.13.3 is in:
/Users/<username>/Library/Python/2.7/lib/python/site-packages
When I run the python interpreter from the command line, it imports the newer version, but when I run a jupyter notebook, it imports the older version. I've checked the sys.path using both methods, and they are the same. This further confuses me because in sys.path the directory for the newer version comes BEFORE the directory for the older version. Based on how I thought sys.path works, that would mean jupyter notebook should be importing numpy from the directory with the newer version in it.
I found another question where someone ended up just renaming the directory with the old version in it, but I'd rather not do that (and also am not sure I have permission to do that anyway).
Can anyone help explain what is going on here, and suggest some solutions?

Please read this long post from Jake Van der Plas describing how importing works and why you think Jupyter is using the wrong numpy.
Once you get how things works, you should be able to fix it following the instructions in Jake's post.

Related

Problms of Anaconda with Different versions of numpy

I'm so sorry to bother you with my stupid question. Due to my mismanagement of the anaconda installation package location, I may have used pip and conda to install numpy many times.
But now, after I manually corrected the installation location, numpy1.20.3 was correctly installed in E:\Anaconda\Lib\ site-packages\numpy. It seems that the problem has been solved, but when I opened the Anaconda pkg folder, I found a lot of files related to the 1.15 version of numpy.
I am very curious and want to know whether I can delete these files manually, and only keep the 1.20 version of numpy? I also want to know how these files are generated, are they the undeleted files left when I uninstalled the old version of numpy with conda or pip before?
Hope you won't be bothered by my stupidity.I would be very grateful if you could share some understanding on these issues!
enter image description here
enter image description here
I looked over your problem and it's safe to say that, you can manually delete all the files of the older version of your Numpy (1.15).
Those files are kept by your machine by default, in case you re-install the
particular version for everything to function and works properly.
It had happened to me too, in my case, it was some other module but the same problem.

Python and modules have different paths

I am learning Python specifically for data science and have little programming language although I'm a bit more familiar with R.
I installed some modules e.g. pandas and matplotlib, using the code:
python -m pip install [name_of_package]
which appear to be successfully installed, however, the console cannot find the packages when I type: import pandas
What I discovered was that the packages and Python have different paths.
For Python, the path is:
C:\Users\stone\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9
For the packages, the path is:
c:\users\stone\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages
I believe the different paths are responsible for Python not finding the packages.
My question, therefore, is how can I point pip to install in the Python path? In other words for the import to be successful.
This entry seems to be similar to my question but the answers are confusing and may have been become out of date. If answering, please be explicit with the code. I'm very new to this.
Note: I really don't want to install it in a virtual environment because it is needed presently.
Thank you in advance.
Python is probably not finding your pandas library, because it's installed in a folder where python is not looking into by default.
When you type "import pandas" python is going to look for a package named pandas within a list of folders set by default.
To solve your issue you can move/reinstall pandas into a folder which python searches through by default or you can add another folder to search through.
Here's a way to do it with python adding directory to sys.path /PYTHONPATH
I am the original poser of the question and found a simple solution that worked for me based on the recommendation of python.org.
First, I uninstalled all python programme from my system
During the reinstall, I checked the box to allow adjust the system PATH environment variable
After installing, I used the `python -m pip install
[name_of_package] to install the pandas packages.
These solved the problem and I am now able to import packages without an error message.
The current path to packages is now:
c:\users\stone\appdata\roaming\python\python39\site-packages

Cannot import sklearn in my jupyter notebook

I installed anaconda and started working on jupyter notebook.
When i try and import sklearn i get the error shown in the image (note that i didn't had any problems importing other packages).
I've done a bit of research online and from my understanding i believe the issue exists because i already have sklearn installed on Python and there's a possible conflict.
If that's the case i don't know what to do since i already use sklearn on another project and i cannot uninstall it.
Anyone know how i can solve this issue?
Thanks in advance!
As you can see from the traceback, there are two python environments involved here:
~\AppData\roaming\python\Python37
~\anaconda3
Please make sure your PATH is clean and you can actually remove one of them first.
For anyone that might face the same issue, check your Anaconda and Python.
I had Anaconda on 64-bit and i didn't knew that by default Python is downloaded on 32-bit.
After uninstalling and installing Anaconda to 32-bit everything worked fine

Python on Mac: How should I manage same modules in different directories?

I am having problems figuring out what is the best practice for handling duplicate modules with different version in different directories.
What I have done and figured out so far is the following.
I updated numpy on my Mac X (Mavericks) using pip which installed the latest version (v1.8.2) of numpy in the following directory:
/Library/Python/2.7/site-packages
When I tried importing numpy in an interactive session, however, python imported the old version (v1.6.2) from the following directory:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
It seems like this happened because python searched for numpy in the second directory before discovering the newer version in the first directory.
According to a a previous post, you can let python load the newer numpy by change the order of search or by deleting the directory which contains the old module. However some say that It is not a good idea to modify the contents of /System/Library/Frameworks.
So what is the best thing to do?
Changing the order of the search seems like a good idea because it will not alter any files or directories, but will it cause any problems if I do that?
Or is there anything else that can solve the problem?

Can't import library in Python - Ubuntu 12.04

I have been trying for 3 days now with now luck, I really am desperate.
I have installed NumPy, along with matplotlib. I am trying to include matplotlib into my applications, but it does not work. I am using Eclipse with the PyDev plug-in, but whenever I try to import it, I get an error, even though I have added it to the libraries that it needs to import every time.
I am a beginner with Linux and I don't really know how to do stuff of the top of my head. I would like to know if this is related to PYTHONPATH and if so, how can I change it?
Also, when running whereis matplotlib, I get matplotlib: usr/share/matplotlib.
EDIT
Even though I did not manage to solve the problem, nor am I interested any more, I consider this question closed. I have decided to use the free version of PyCharm, as suggested by #FooBarUser.
On my Ubuntu 12.04, modules like these are installed in /usr/local/lib/python2.7/dist-packages. Adding that to PYTHONPATH may help resolve the issue.In my ~/.bashrc I have
export PYTHONPATH=...
export PYTHONPATH=/usr/local/lib/python2.7/dist-packages:$PYTHONPATH
export PYTHONPATH=
Edit: if you also have Python 3 installed on your system, numpy might also be in
/usr/lib/pyshared/python2.7/numpy
If the latest version of numpy was built to be backwards compatible with both 2.7 and 3.*, the installer might put it in that directory which is meant for packages which can be shared across multiple python version numbers.

Categories