I'm running Centos7 and it comes with Python2. I installed python3, however when I install modules with pip, python3 doesn't use them. I can run python3 by typing python3 at the CLI
python (2.x) is located in /usr/bin/python
python3 is located in /usr/local/bin/python3
I tried creating a link to python3 in /usr/bin/ as "python", but as expected, it didnt resolve anything. I renamed the current python to python2.bak It actually broke some command line functionality (tab to complete). I had to undo those changes to resolve.
Suggestions welcome. Thanks.
The IUS project has ready to go RPM packages of python34u-pip, python35u-pip, and python36u-pip. These will give you corresponding pip3.4, pip3.5, and pip3.6 commands. As expected, the packages installed by those will be available to the corresponding python3.4, python3.5, and python3.6 interpreters.
Do you have pip for python3, too? Try pip3 rather than pip. I assume your regular pip is just installing the modules for Python 2.x.
Related
I've been trying to use VS Code's python debugger on Linux (mint), which uses debugpy and it keeps giving the error "No module named '_ctypes'". Installing libffi-dev didn't fix it as suggested elsewhere on SO and neither did reinstalling python and python3; so, I tried installing debugpy through pip:
pip install debugpy
Which installs with no issues. However, both python and python3 commands cannot find the module despite the fact that the module is installed (which I can see when I enter pip list)
python -m debugpy
/usr/bin/python: No module named debugpy
python3 -m debugpy
/usr/local/bin/python3: No module named debugpy
So after trying to reinstall pip multiple times, I tried installing through the pip module
python -m pip install debugpy
/usr/bin/python: No module named pip
python3 -m pip install debugpy
/usr/local/bin/python3: No module named pip
So it seems my pip module is also missing too. It may have something to do with my multiple installations of python3 as it seems that there is one in /bin and in /usr/local/bin and the local installation is the one that gets called with the python3 command according to which python3.
This leads to multiple questions:
Should the pip module be installed in python, and if so how do I install it again?
How can I get the pip command to actually install the modules into python?
How can I ensure that there is only one python3 installation in Linux (mint/ubuntu)?
Thank-you. If it helps answer the question, I do not seem to have a PYTHONPATH variable.
i had same issue but it can be fixed by two methods.
reinstall pip for the latest python version you use.
2.use the version default python version which came with your python install
On ubuntu you can try to do sudo apt install python-pip python3-pip. Also there a couple ways you can try what PIP's documentation recommends: Installation
You can try checking sudo update-alternatives --config python maybe you'll see several python installations there.
Also you can check pip contents to find out what python binary it uses:
$ which pip
/usr/local/bin/pip
$ cat /usr/local/bin/pip
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/usr/bin/python3
I tried installing it with pip and it has worked for me. The problem you might have is that it is not installed in the correct version of python (e.g it installs for python2 instead of python3 or it installs in python3.8 instead of python3.9).
What you can do to avoid this problem is to create a virtual environment, as is explained in this link: https://docs.python.org/3/tutorial/venv.html. If you do that, remember to change the interpreter path in VSCode. At the bottom left of the screen there should be the python version that you are using. If you click on it you see different interpreter versions that you can use. Select 'Enter interpreter path' and manually choose the directory where you have saved the new python virtual environment.
It's difficult to narrow down a solution for apparently you have done a mess... To start, do yourself a favor:
Don't touch your System's Python!
Again, it is difficult for me to understand what is the current state of your Python scene... just promise me you'll fix your System's Python 2/3 (i.e, guarantee pip 2/3 there, using your system's package manager (apt, yum, etc)).
Then, start using some virtual environment manager, nowadays we have Pipenv (https://pipenv.pypa.io/), which can be a bit cumbersome at first but -- trust me -- in ~1 hour you'll love it.
Conda (https://docs.conda.io/) is also a great env manager (or the classics (pyenv, venv, etc...)).
...Just pick one and leave your OS' Python alone. You'll see that your issues will not only get simpler to diagnose but you'll also be able to sleep in peace ;)
[On a mac]
I know I can get packages doing pip install etc.
But I'm not entirely sure how all this works.
Does it matter which folder my terminal is in when I write this command?
What happens if I write it in a specific folder?
Does it matter if I do pip/pip3?
I'm doing a project, which had a requirements file.
So I went to the folder the requirements txt was in and did pip install requirements, but there was a specific tensorflow version, which only works for python 3.7. So I did """python3.7 -m pip install requirements""" and it worked (i'm not sure why). Then I got jupyter with brew and ran a notebook which used one of the modules in the requirements file, but it says there is no such module.
I suspect packages are linked to specific versions of python and I need to be running that version of python with my notebook, but I'm really not sure how. Is there some better way to be setting up my environment than just blindley pip installing stuff in random folders?
I'm sorry if this is not a well formed question, I will fix it if you let me know how.
Yes, there is. Setup an virtual environment.
pip install virtualenv #installs the library
virtualenv mypython #creates the environment
source mypython/bin/activate #activates the environment
Now, install your requirements through pip.
Afterwards, when your work is finished.
Just type deactivate to come out of the virtual environment.
There may be a difference between pip and pip3, depending on what you have installed on your system. pip is likely the pip used for python2 while pip3 is used for python3.
The easiest way to tell is to simply execute python and see what version starts. python will run typically run the older version 2.x python and python3 is required to run python version 3.x. If you install into the python2 environment (using pip install or python -m pip install the libraries will be available to the python version that runs when you execute python. To install them into a python3 environment, use pip3 or python3 -m pip install.
Basically, pip is writing module components into a library path, where import <module> can find them. To do this for ALL users, use python3 or pip3 from the command line. To test it out, or use it on an individual basis, use a virtual environment as #Abhishek Verma said.
I'm using a remote server, which some others use together.
There are several versions of python installed.
I need python 3.6 version, and I can run it with /bin/python3.6 command.
And I also want to make a virtualenv of the version, so I tried /bin/python3.6 -m pip --version
But it showed
/bin/python3.6: No module named pip
When I checked the lib directory, ll /usr/lib/python3.6/site-packages/
total 0 drwxr-xr-x 2 root root 6 Dec 20 2017 __pycache__
It seems that the server has python3.6, but misses pip for that, right?
How can I resolve this, with the minimum modification?
The server is centos7.
Any thought or comment appreciated :)
As drum mentioned at the comment, I installed pip referring to pip.pypa.io/en/stable/installing.
I ran the python file with /usr/bin/python3.6 get-pip.py.
After installing virtualenv, I faced virtualenv not found error.
You can solve the above error with the following link.(It was a path issue) Virtualenv Command Not Found
In case you don't want to modify the system Python you can just use the zipapp version of virtualenv to create a virtual environment at some arbitrary location with latest pip included (see https://virtualenv.pypa.io/en/latest/installation.html#via-zipapp).
wget https://bootstrap.pypa.io/virtualenv/virtualenv.pyz
python3.6 /full/path/to/downloaded/virtualenv.pyz ~/virtualenv
~/virtualenv/bin/python -m pip list
That's probably the minimum harmful modification, and ensure that messing with the system python does not break your system python applications/environment.
I haven't tried yet out of fear I'll mess up more than I'll fix but I don't know if I can use PYTHONPATH to fix my problem. I've installed python 2.7.10 and python 3.4.2 on my Macbookpro. Python2.7 doesn't have problems, only 3.4 does. I'm afraid if I use PYTHONPATH to fix python3, it will affect python2.
Anyway, I've run:
sudo pip install blah2
sudo pip3 install blah3
pip freeze | grep blah2
blah2=2.12345
pip3 freeze | grep blah3
blah3=3.12345
and I can see I've installed the respective modules for python2 and python3 as pip freeze has shown.
However, I keep getting errors when running scripts from cmd line for python 3.4 that say the module isn't found.
On further investigation using sys.path in my script, I can see python3 from cmd line is looking for modules at
/usr/local/lib/python3.4/site-packages
which doesn't have anything inside of it, whereas Idle for python 3.4 is looking at
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
which has tons of files in there.
I don't know why this got messed up in the first place or what I forgot to do to mess it up like this but how do I tell python 3.4 to look at the /Library location for modules?
The funny thing is both python2 and 3 were installed from tar/gzip files. I ran both using the
configure; make ;make install
command but for some reason python2 is fine but python3 isn't.
This may mean the pip3 is installing to that different path.
Take a look at pip3 script and see where it is putting the package files. In my case the first line of it looks like this:
#!/opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
Look if this is the path to the correct python3 binary. If it's not, you have two options: change this first line of pip3 to the path of your desired python3 binary, or just forget about it, use the pip directly with python3 command:
python3 -m pip install blah3
This should use the appropriate path when installing the package.
I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?
Thanks
...I get a bash error python331/bin/pip No such file or directory.
It's still looking for pip in the python3 install. How can I remedy
this?
bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...
$ type pip
...you get something like...
pip is hashed (python331/bin/pip)
...you just need to clear the hash table for bash with...
$ hash -r
...then it'll pick up the version in Python 2.7 the next time you try to run pip.
Fixed it.
Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7