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
Related
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
I am trying to install NLTK package in Python 2.7 - I already have it installed in Python 3. So every time I run :
sudo pip install nltk
I get:
Requirement already satisfied: nltk in
/anaconda/lib/python3.6/site-packages
Requirement already satisfied: six in
/anaconda/lib/python3.6/site-packages (from nltk)
How do i specifically install nltk in python 2.7 instead?
Thanks a lot!
Jay
The easiest way for install the nltk module with Python 2.7 version is this one:
sudo pip2 install nltk
It will automatically recognize your Python 2.7 version. But you can also be more specific if you have more than one version for Python 2. In that case you could change pip2 to pip2.7. In general the PIP command from version 1.5 supports the pipVERSION argument (see below some examples for different versions of Python environment):
$ pip2.6 install SomePackage # Python 2.6
$ pip2.7 install SomePackage # Python 2.7
$ pip3.6 install SomePackage # Python 3.6
How to solve the sudo:pip2 command not found
(IMPORTANT: be sure of have the correct version of Python 2.7 installed. If you are not sure, please just download it from : https://www.python.org/download/releases/2.7/. For example if you are on Mac machine you need for sure to download it again cause the default version already installed doesn't work properly sometimes with NLTK module).
As the user #kittcar encountered this kind of error I'll show a couple of solutions for find a way around the problem:
The first option is to type on command line: easy_install pip
This will automatically install all the dependencies for your current Python versions. (See the picture below)
IMPORTANT: If you don't have the easy_install command just run:
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
The second option (if for some reasons the first option doesn't work) is to type:
curl -O https://bootstrap.pypa.io/get-pip.py and
python27 get-pip.py
Basically you take the source from the target url and then you install PIP for Python 2.7 version.
The third option is to use the conda instead of pip command if you use (like in my personal case) the Anaconda Environment and you want to install the nltk module fastly. In that case you just need to follow these steps:
Download the zip source: https://gist.github.com/danielfrg/d17ffffe0dc8ed56712a0470169ff546.
Extract the folder and rename as "nltk-with-data".
Change directory to one directory above the nltk-with-data directory with cd command.
Run conda build for different Python versions that you need, selecting the packages for the platform and OS you are running the command on.
Below the command list:
conda build nltk-with-data --python 2.7 # you need this one! :-)
conda build nltk-with-data --python 3.4
conda build nltk-with-data --python 3.5
conda build nltk-with-data --python 3.6
Finally you just need to run conda install nltk-with-data and ipython for conclude the nltk installation. And then you just need to type:
import nltk.corpus
nltk.corpus.treebank
As you can see from my screenshot everything went fine and I have successfully installed the nltk module for Python 2.7 with the Anaconda Environment:
Feel free to ask me everything, in particular let me know if you successfully fixed your problem or not. If not, please update your question with command line error logs and your current machine details. So I can understand better what exactly causes your problem and I can suggest you the worth solution for solve it.
Unfortunately, the solutions given in the 2 answers posted above did not work for me. Both pip and pip2 were installing the same new version of nltk that was not compatible with python2.7. Thankfully, the accepted answer of another question, Install older (but stable) NLTK version compatible with python 2, solved the problem. The solution is to specify explicitly the version of nltk to be installed when using the pip command:
pip install nltk==3.4.5
Versions of nltk higher than 3.4.5 happen to be incompatible with Python 2
you should use different pip for python 2 and 3. Or just virtual env.
Anyway, another possible idea to Giulio Bambini's response is:
python2.7 -m pip install <module>
with
sudo
if necessary
I'm using Kali dist so I have already installed Python 2.7, 3.5 and 3.6. Commands 'python' and 'pip' are associated with Python 2.7. But the 'python3' uses Python 3.6 while pip3 is installing packages for Python 3.5.
When I tried to create an venv:
pip3 -p python3.6 virtualenv myenv
I've got an error:
no such option: -p
How can I associate pip3 with Python 3.6 instead of Python 3.5?
Your version of pip is inextricably linked to your version of Python, you cannot tell pip "use this Python" or "use that Python." If you have a version mismatch between pip3 (using Python 3.X) and python3 (being Python 3.Y), it means your problem is with multiple overlapping distributions of Python and a weirdly configured $PATH.
If you run pip3 --version it will tell you the site-packages directory and Python version number that pip3 is associated with.
If you run python3 and then execute >>> import site; site.getsitepackages(), it should print the site-packages directory your python3 is using.
If these do not match, you've got path problems and you'll need to post more information about what operating system you're on, what Python distributions you're using, and how you installed them.
Update/Summary of Comment Thread: Original poster had a distribution-bundled Python 3.6 installed alongside a self-installed Python 3.5. The pip3 on their path was associated with Python 3.6 (system Python), while the command python3 was associated with Python 3.5 (their self-installed Python). Resolution:
Run which -a python3 to find Python 3.5. Add the location of Python 3.5 to your $PATH. (Do it in .profile or .bash_profile to make it permanent.)
You can explicitly run the pip3 script with a particular Python version, by prefixing it with the appropriate python3.x command:
ldo#theon:~> pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
ldo#theon:~> python3.5 $(which pip3) --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
To install a package in the same version location that's associated with the version associated with python3, use the following:
python3 -m pip install [package]
to pick a specific version that you'd like your package to be associated with (so you're not guessing with the above):
python3.5 -m pip install [package]
python3.7 -m pip install [package]
Also, be careful because pip3 can point to different locations and may not necessarily match the location of the python3 binary. I just found that out when I did a pip3 install and it failed to import when running python3.
You can also explicitly call pip3.5, pip3.7, etc, but honestly I prefer using the python[version] -m pip install [package] method because I know that it will install the package in the location associated with whatever python3.x binary I'm using.
When you install Python3, see if there's a comment such as this:
Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS
You might see entries like this in the log:
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3 _ssl
_tkinter readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
This answer describes using ensurepip
https://stackoverflow.com/a/38250442/1607937
Also see this regarding openssl
"SSL module in Python is not available" when installing package with pip3
If you want to use only one version of python you sould probably create an alias. Add this line at the end of your ~/.bashrc flie:
alias pip='python3.6 -m pip'
Then, run source ~/.bashrc, and now pip --version will show something like:
pip xx.x.x from /usr/lib/python3/dist-packages/pip (python 3.6)
you can update line #1 from /usr/bin/pip3 to #!/usr/bin/python3.8 as below
#!/usr/bin/python3.8
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
First find the right version of python you want to use:
$ which -a python3.6
/usr/bin/python3.6
then invoke that instance of python directly, e.g.
$ /usr/bin/python3.6 -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR
Next, pip does not create virtual environments. The module venv does. Read the venv documentation for recommended usage. In your case, you might want:
$ /usr/bin/python3.6 -m venv myenv
I am using Python 2.7.12 and I want to check whether the pip is installed or not. For this, in command line of Python application I wrote pip list and pressed enter. However, I get an error like:
File"stdin",line 1
pip list
Syntax Error: invalid syntax
So, how can I solve this issue and get the list of modules as an output?
Thanks
Use command line and not python.
TLDR; On Windows, do:
python -m pip --version
OR
py -m pip --version
Details:
On Windows, ~> (open windows terminal) Start (or Windows Key) > type "cmd" Press Enter
You should see a screen that looks like this
To check to see if pip is installed.
python -m pip --version
if pip is installed, go ahead and use it. for example:
Z:\>python -m pip install selenium
if not installed, install pip, and you may need to add its path to the environment variables. (basic - windows)
add path to environment variables (basic+advanced)
if python is NOT installed you will get a result similar to the one below
Install python. add its path to environment variables.
UPDATE: for newer versions of python
replace "python" with py - see #gimmegimme's comment and link
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
If you are on a linux machine running Python 2 you can run this commands:
1st make sure python 2 is installed:
python2 --version
2nd check to see if pip is installed:
pip --version
If you are running Python 3 you can run this command:
1st make sure python 3 is installed:
python3 --version
2nd check to see if pip3 is installed:
pip3 --version
If you do not have pip installed you can run these commands to install pip (it is recommended you install pip for Python 2 and Python 3):
Install pip for Python 2:
sudo apt install python-pip
Then verify if it is installed correctly:
pip --version
Install pip for Python 3:
sudo apt install python3-pip
Then verify if it is installed correctly:
pip3 --version
For more info see: https://itsfoss.com/install-pip-ubuntu/
UPDATE
I would like to mention a few things. When working with Django I learned that my Linux install requires me to use python 2.7, so switching my default python version for the python and pip command alias's to python 3 with alias python=python3 is not recommended. Therefore I use the python3 and pip3 commands when installing software like Django 3.0, which works better with Python 3. And I keep their alias's pointed towards whatever Python 3 version I want like so alias python3=python3.8.
Keep In Mind
When you are going to use your package in the future you will want to use the pip or pip3 command depending on which one you used to initially install the package. So for example if I wanted to change my change my Django package version I would use the pip3 command and not pip like so, pip3 install Django==3.0.11.
Notice
When running checking the packages version for python: $ python -m django --version and python3: $ python3 -m django --version, two different versions of django will show because I installed django v3.0.11 with pip3 and django v1.11.29 with pip.
$ which pip
or
$ pip -V
execute this command into your terminal. It should display the location of executable file eg. /usr/local/bin/pip and the second command will display the version if the pip is installed correctly.
pip list is a shell command. You should run it in your shell (bash/cmd), rather than invoke it from python interpreter.
pip does not provide a stable API. The only supported way of calling it is via subprocess, see docs and the code at the end of this answer.
However, if you want to just check if pip exists locally, without running it, and you are running Linux, I would suggest that you use bash's which command:
which pip
It should show you whether the command can be found in bash's PATH/aliases, and if it does, what does it actually execute.
If running pip is not an issue, you could just do:
python -m pip --version
If you really need to do it from a python script, you can always put the import statement into a try...except block:
try:
import pip
except ImportError:
print("Pip not present.")
Or check what's the output of a pip --version using subprocess module:
subprocess.check_call([sys.executable, '-m', 'pip', '--version'])
You need to run pip list in bash not in python.
pip list
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
argparse (1.4.0)
Beaker (1.3.1)
cas (0.15)
cups (1.0)
cupshelpers (1.0)
decorator (3.0.1)
distribute (0.6.10)
---and other modules
In CMD, type:
pip freeze
And it will show you a list of all the modules installed including the version number.
Output:
aiohttp==1.1.4
async-timeout==1.1.0
cx-Freeze==4.3.4
Django==1.9.2
django-allauth==0.24.1
django-cors-headers==1.2.2
django-crispy-forms==1.6.0
django-robots==2.0
djangorestframework==3.3.2
easygui==0.98.0
future==0.16.0
httpie==0.9.6
matplotlib==1.5.3
multidict==2.1.2
numpy==1.11.2
oauthlib==1.0.3
pandas==0.19.1
pefile==2016.3.28
pygame==1.9.2b1
Pygments==2.1.3
PyInstaller==3.2
pyparsing==2.1.10
pypiwin32==219
PyQt5==5.7
pytz==2016.7
requests==2.9.1
requests-oauthlib==0.6
six==1.10.0
sympy==1.0
virtualenv==15.0.3
xlrd==1.0.0
yarl==0.7.0
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