Cannot find the updated python module - python

I have installed the latest version of Python numpy module but when i tried to look for the version of the new numpy module, it still shows me the old version.
sudo pip install 'numpy==1.9.0'
python -c "import numpy; print numpy.__version__"
1.8.2
Here are my Python and pip versions
python --version
Python 2.7.6
pip --version
pip 8.1.2
Am i missing something here?

The version of pip you are using is not associated with the version of Python you're using. pip is installing NumPy into the miniconda distribution (BTW, are you aware that the latest version of NumPy is 1.11.3?), whereas your Python binary is reading its site-packages from elsewhere. To determine this, run
python
at the command prompt, then once in the interpreter run
>>> import sys
>>> print(sys.executable)
>>> from pprint import pprint as pp # makes reading the results easier
>>> pp(sys.path)
sys.executable will tell you which python binary you're running, and the sys.path list will tell you from where Python is importing its packages.
All this being said, you need to point your pip script to the version of Python you're actually using. The easiest way (IMO) is to download get-pip.py, then run either
python get-pip.py
(after changing to the download directory) or
sudo python get-pip.py
depending on whether you're an admin or not. This will install the latest version of pip (currently 9.0.1) and associate it with the version of Python that was used to call the script.

Related

Both commands give `Requirement already satisfied`

I was trying to install a package called configparser on my local machine. Now, I have both Python 2.7 as well as Python 3.7.4 on my machine. Hence I wanted both versions of configparser to be installed.
I have set the default python version to be Python 3.7.4. So I used this command first:
1.pip3 install configparser:
which gave me requirement satisfied since I already had installed it.
Now, when I use:
2.pip install configparser:
it tells me that requirement is satisfied. But there is now package called configparser in Python 2.
What do I have to do to install the Python2 version of configparser on my machine?
Thanks in advance.
P.S: I use Windows 10, develop in PyCharm.
Also, pip -V gives me:
pip 19.1.1 from c:\users\ymodak\appdata\local\programs\python\python37-32\lib\site-packages\pip (python 3.7)
you need to set the path of your envernnement variable to where python 2 is installed
or do this "path to pip in python2 directory"/pip install "Package"
if you want to configure pip to install packages on python 2 and pip3 to install packages on python3 you need to delete pip in python 3 directory and set both of paths in environnement variable python2 (path to pip in python2 directory) and python3 (path to pip3 in python3 directory)
It used to be that normally, 'python', 'pip' (and also 'ipython' if you use that) would be python 2, and to use python3, you have to explicitly say 'python3', 'pip3', 'ipython3'.
I have noticed recently (on Macs at least) that this is not necessarily still the case... on my Mac after installing 3.6.3, 'python' still points at a 2.7.15 install, but 'ipython' and 'pip' both point at the python3 version. This is just a general note that when mixing versions, you can end up with all kinds of mixed pointers to things - in my case, I have a system python at /usr/bin/python that's 2.7.10, a homebrew-installed python 2 that's 2.7.15, and a 3.6.3 installation installed from the .pkg on the official python site.
However, in every case, usually they are all installed with explicit versioning as well, so you should be able to do e.g.
pip2 install configparser
pip3 install configparser
or even
pip2.7 install configparser
pip3.6 install configparser
pip3.7 install configparser
etc. to point directly at a specific version.
You also can (per one of the other answers) call it as a module from any python version e.g.
/my/path/to/a/custom/python -m pip install configparser
and that will guarantee to put it in whatever path that python requires - on my system, I have two python 2.7 versions installed; pip2.7 points to the one in /usr/local/bin/python2.7, which is a 2.7.15 install. There is no pip2.7.10 - it only goes to the first subversion - but I can manually do
/usr/local/bin/python -m pip list
/usr/bin/python -m pip list
and get two different lists of installed modules, as each one has its own site-packages area. So that is always an option.
in python 3, use
python3 -m pip install configparser
assuming that python3 is keyword to call python 3.7
in python2, use
python -m pip install configparser
assume python is keyword to call python2

Python loading old version of sklearn

I've installed version 0.18.2 of scikit-learn on my Mac using
pip uninstall scikit-learn
pip install scikit-learn==0.18.2
However, when I run
python
>>> import sklearn
>>> sklearn.__version__
I get
'0.17'
Interestingly, this older version is still installed even after I uninstall scikit-learn. Could this have something to do with multiple versions of Python somehow being installed? I beat my head against the wall trying to use Anaconda at one point to try to get numpy and scipy running, and have since switched to ActivePython. When I run
which python
I get
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
I know there are very similar questions on SO, but none of the posted solutions have worked.
You have to make sure that the pip you are invoking is the pip executable that belongs to the python that you are invoking. Otherwise, you're installing python packages to the wrong version, if you have multiple versions on your machine.
pip --version will list the Python version associated with whatever pip you invoked.
python -m pip install scikit-learn --upgrade will use whatever python you're invoking to invoke its own installation of pip (if it exists). This should work in your use case because it lets you not worry about whatever your pip maps to.
Check your python path. On unix:
echo $PYTHONPATH
This will output all paths used for module imports. You might have some old version installed elsewhere.

Python3 does not find modules installed by pip3

I'm having problems with python3. For some reason that I cannot figure out, the modules available in python3 are not the same as the ones installed via pip3.
Running pip3 list in a Terminal returns:
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
nltk (3.2.2)
numpy (1.12.0)
pandas (0.19.2)
pip (9.0.1)
python-dateutil (2.6.0)
pytz (2016.10)
setuptools (25.2.0)
six (1.10.0)
wheel (0.29.0)
Running this script to see what modules python3 has available returns:
['cycler==0.10.0', 'matplotlib==1.5.3', 'nltk==3.2.1', 'numpy==1.11.2', 'pip==9.0.1', 'pyparsing==2.1.10', 'python-dateutil==2.6.0', 'pytz==2016.7', 'setuptools==18.2', 'six==1.10.0']
These two are not the same and I can't tell why. nltk, for example, has an older version. pandas is missing.
I've installed python via homebrew and I'm running scripts via Textmate2. However, I have the same problem when I run code in terminal, via python3. Both pip3 and python3 are installed in /usr/local/bin/:
$ which python3 pip3
/usr/local/bin/python3
/usr/local/bin/pip3
And that's also the version python3 is using:
>>> import sys, os
>>> os.path.dirname(sys.executable)
'/usr/local/bin'
If someone could help me figure out why this is the case, and how I can fix it, I would very much appreciate the help.
Look at the first line of the pip3 script.
The first line (starting with #! should point to the same executable as the symbolic link for python 3:
> head -n 1 /usr/local/bin/pip
#!/usr/local/bin/python3.6
> ls -ld /usr/local/bin/python3
lrwxr-xr-x 1 root wheel 9 Dec 25 22:37 /usr/local/bin/python3# -> python3.6
If this is not the case, deinstall pip and install it again with the correct Python version.
EDIT:
If you really want to make sure that you're using the the right Python with pip, then call it as a module like this:
python3.7 -m pip list
If you get the error No module named pip, then pip is not installed for this version of python.
I ran to this problem in Windows. first of all I uninstall the package using cmd command pip3 uninstall moduleName.
Then based on python documentation I run command python -m pip install moduleName and my problem solved!
Here is the documentation: Installing Python Modules

Does the python.org installer of python come with pip, and how do I use it?

I can download python 2.7.12 from python.org, and all python versions from 2.7.9 onwards are supposed to come with pip, but after installing it, using pip in the terminal does not work.
I am on macOS.
Have I installed pip, and if I have, how do I use it?
Here you have informations about pip:
https://packaging.python.org/installing/
normally python from python.org come with pip, maybe you should just update...
to update from terminal:
pip install -U pip setuptools
After when you need to install package, for example numpy, just do in a terminal:
pip install numpy
more informations here :
https://pip.pypa.io/en/stable/reference/pip_install/
you can also use conda install from anaconda as an alternative of pip :
http://conda.pydata.org/docs/get-started.html
Multiple instances of Python can coexist on your machine. Thus you could have installed Python 2.7.12 yet, when you call Python from terminal, you may be calling an older version.
To know which version you are using, type which python in terminal and look at its path. Then from Python in terminal, type
import sys
print(sys.version)
to get the exact version.
As Dadep says, I would recommend using conda to isolate your invironments if you have to play with multiple Python interpreters. Further conda simplifies 3rd party package installation process beyond doubt.

Python - no module named setuptools

I'm trying to install modules on an alternate version of Python (3.3.0) I have installed on my Mac (OS X 10.7.4). The new version of Python runs OK in the IDLE and also in Terminal:
However, trying to install something relatively trivial like NumPy only installs in the old pre-installed version of Python on my Mac (2.7.1).
Executing this:
$ python3.3 easy_install numpy
Gives me this error message:
/Library/Frameworks/Python.framework/Versions/3.3/Resources/Python.app/Contents/MacOS/Python: can't open file 'easy_install': [Errno 2] No such file or directory
I then read that creating a virtual environment is the way to go, so I tried that:
$ mkvirtualenv python=python3.3 foo
It returned this error:
-bash: mkvirtualenv: command not found
So, I clearly don't have that installed correctly, either (virtualenv-1.8.4).
There is probably lots more homework that I need to do, but I don't really have any intention of using 2.7 ever again, just Python 3 so I don't need to go back and forth. At the same time I know that I need to keep the old version of Python on my Mac for whatever reason, so I don't intend to delete it. Any suggestions for what I'm missing would be very helpful.
Try with this:
easy_install numpy
easy_install is a shell script, not a python script.
I solved this by using Anaconda from Enthought. It had all the plugins and such that I needed. Thanks for everyone's suggestions and help! :)
You have the wrong command. Instead of:
$ python3.3 easy_install numpy
you want:
$ easy_install3 numpy
or even more specific:
$ easy_install-3.3 numpy
But you shouldn't be using easy_install in the first place:
$ pip3 install numpy
or more specific than pip3:
$ pip-3.3 install numpy
If you look deeper, you'll see that both pip3 and pip-3.3 are the same:
$ pip3 --version
pip 1.2.1 from /usr/local/lib/python3.3/site-packages/pip-1.2.1-py3.3.egg (python 3.3)
$ pip-3.3 --version
pip 1.2.1 from /usr/local/lib/python3.3/site-packages/pip-1.2.1-py3.3.egg (python 3.3)
and both easy_install3 and easy_install-3.3 are the same:
$ easy_install3 --version
distribute 0.6.32
$ easy_install-3.3 --version
distribute 0.6.32

Categories