Can't get pip to work after installing newer python - python

I installed python 3.8 in a different location than 3.7, and later uninstalled 3.7 while trying to troubleshoot issues with pip. I can't get pip to respond to install any modules now. It keeps referencing its old python 3.7 location and I don't know how to make it focus on the 3.8 installation location.
Here are the errors I'm encountering:
>pip --version
Fatal error in launcher: Unable to create process using '"c:\program files\python37\python.exe" "C:\Program Files\Python37\Scripts\pip.exe" --version': The system cannot find the file specified.
>python get-pip.py
Collecting pip
Using cached pip-20.1.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.1.1
Uninstalling pip-20.1.1:
Successfully uninstalled pip-20.1.1
Successfully installed pip-20.1.1
Now when I call pip --version is gives me the original error.
And just for more information, here are two more calls which might help troubleshoot.
>which python
/c/Users/patch/AppData/Local/Programs/Python/Python38/python
>python --version
Python 3.8.3
I just want to be able to use pip again to install modules. I'm learning some python and this pip issue is really slowing me down.
I'm open to completely uninstalling python and scrubbing the system of traces of both I just don't know what's the safest and most likely to work option.

Use
python -m pip --version
python -m pip install PACKAGE_NAME
This will use the pip that is associated with the newer python.
I suggest using the python -m pip install command over pip install because it is more clear which python version is being used.

I'd recommend scrubbing 3.7 and 3.8 from your system, then reinstalling the versions you need with pyenv (if you're using the Windows Subsystem for Linux) or pyenv-win (if not on WSL) to manage multiple Python versions. It checks the directory-specific version of Python that you've set before deciding which version's executables to use for Python, pip, etc. This solution will also work in the long term for future versions of Python you may want to install.
Future installations using pyenv or pyenv-win would involve commands like pyenv install 3.8.1. For a full list of available versions you can run pyenv install -l.
#jakub's solution will work if you want an immediate, but short-term, fix.

Related

AWS cloud9 pip install goes to python 2.7 instead of 3.6

this question is specifically for aws cloud9. Everything looks fine prima-facie, but it's creating a lot of problems.
When i am checking python version, it's showing the correct version (without using python3)
xxxx#yyyyy.zzz:~/environment $ python --version
Python 3.6.8
When i am using which python, it's showing the correct (desired) python version
xxxx#yyyy.zzz:~/environment $ which python
alias python='python36'
/usr/bin/python36
When i am checking pip version, it's showing pip version for python 3.6, but showing a very old version of pip.
xxxx#yyyy.zzz:~/environment $ python -m pip --version
pip 9.0.3 from /usr/lib/python3.6/dist-packages (python 3.6)
When i try to upgrade pip to new version, it goes to python2.7 now (undesirable)
xxx#yyyy.zzz:~/environment $ pip install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages (20.0.2)
so, when i do a pip install of a desired package, it gets installed, but cannot use it in my program as it installs for python 2.7.
I have gone past this issue on my local windows computer a long time ago. However, this is a ec2 default environment that comes when setting up cloud9, and is a linux ubuntu dist (afaik).
Have tried to find out online, but couldn't get a simple answer. I could find answers relating to using virtualenv for these kind of issues. I am wondering if there is a simpler solution to this.
I finally resolved it by unaliasing "python" with python36.
unalias python
Then when i went to ask python version, it gave python 2.7 (as expected)
then i went for
sudo python3 -m pip install --upgrade pip
it finally worked and upgraded pip to latest.
then i could download other libraries using
python3 -m pip install <library-name>
Thanks Arun for your extensive help.
This solution may be a workaround, but it finally made it work. If anyone wants me to find the solution further, i am ready to engage.
python is an alias to point to python36. Looks like you have python 2 and python 3 installed.
python -m pip --version is returning the pip version pointing to python3 because python here refers to python3. If you try python2.7 -m pip --version it will return the pip version corresponding to python2.7
You should rather check pip --version to see the version of pip.
You could install your packages using pip3 install <package-name> or set an alias for pip to point to pip3
which pip3
Once you get the path of pip3, then you can create the alias
alias pip=`<path to pip3>

Unable to install an older version of python

I already have python 3.6.8 and 3.7.3 installed on Windows 10. I had used the "executable installer" from the downloads page to install it.
I have a requirement where I need to install 3.7.1, unfortunately when I use the installer to install python 3.7.1, it complains that "another version of this product is already installed".
How can I install python 3.7.1 without uninstalling 3.7.3?
Have you tried using a virtual environment? This would resolve your problems nicely. Below are the command line steps to create/activate one on Windows.
pip install virtualenv
virtualenv mypython
mypthon\Scripts\activate
If you don't already have pip, use:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
This should resolve your problems, as you can run one version on your vm, and another on your local computer. Let me know if you have any questions!

Virtualenv with pyenv gives wrong python version

I have pyenv installed on an up to date debian testing distribution, and have python 2.7.1 in it.
I create a virtualenv for a project with this version, but when activated it gives me the python system version (3.7).
Here is what I did:
$ pyenv virtualenv 2.7.16 my_project-2.7
Requirement already satisfied: virtualenv in /home/user/.local/lib/python2.7/site-packages (15.1.0)
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Using base prefix '/usr'
New python executable in /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/bin/python
Installing setuptools, pip, wheel...
done.
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Collecting pip
Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.1.1
Uninstalling pip-19.1.1:
Successfully uninstalled pip-19.1.1
Successfully installed pip-19.1.1
$ pyenv activate my_project-2.7
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
$ python --version
Python 3.7.3
$ pip --version
pip 19.1.1 from /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/lib/python3.7/site-packages/pip (python 3.7)
It is strange. The virtualenv is correctly set into ~/.pyenv/version/2.7.16, but I can see that pip come from /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/lib/python3.7/
I think I missed something, or I might have some mess in my python installation, but I can't find out what this python3.7 lib is doing here.
How can I have this virtualenv created for python2.7 ?
Edit
I tried to completely remove pyenv (removing the $(pyenv root) directory), then reinstall it with pyenv-installer but it did not change anything.
I created two virtualenvs for two projects I have (the above 2.7 and one in 3.5).
$ pyenv virtualenvs
2.7.16/envs/my_project-2.7 (created from /usr)
3.6.8/envs/other_project-3.6 (created from /home/user/.pyenv/versions/3.6.8)
my_project-2.7 (created from /usr)
other_project-3.6 (created from /home/user/.pyenv/versions/3.6.8)
I think the problem could be found from this created from /usr but I don't understand what it means. Why was this virtualenv not created from the pyenv python version ? Is it at all relevant ?
It seems that when I create a 3.+ virtual env, venv is used. But on 2.7, virtualenv is used and fails.
WFM as written if I install pyenv and pyenv-virtualenv from scratch according to the linked instructions.
I can see that pip come from /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/lib/python3.7/
This shows that most probably, that virtual environment already exists and has a wrong Python version.
I can only conjecture how it ended up like this. Most probably, you were messing with that virtualenv or with pyenv envvars by hand; or ran scripts/have something in your bash stratup scripts that do that. E.g. if you are using pyenv-virtualenv commands to manage your environments, you are not supposed to mix them with regular virtualenv commands.
Deleting this virtualenv with pyenv virtualenv-delete my_project-2.7 then recreating it should help.
If not, delete ~/.pyenv and everything relevant from your startup scripts, restart the shell and reinstall pyenv and pyenv-virtualenv.
For a less destructive fixing, you need to carefully inspect your shell environment (envvars, aliases, defined shell functions) and startup scripts for anything that might conflict with pyenv's work; if that doesn't help, debug pyenv machinery (export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' helps here very much) to find out what exactly is happening.

brew python versus non-brew ipython

I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python. Also pip is installed via brew, which pip returns /usr/local/bin/pip.
I do not remember how I installed ipython, but I didn't do it via brew, since when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OS X version of ipython?
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python. I do not want to re-install everything again on the brew python, rather continue to install libraries on this version of ipython. How can I install new libraries there? For example, Python Image Library, or libjpeg?
If possible, I would like an exhaustive answer so to understand my problem, and not just a quick fix tip.
I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python.
Okay, good so far.
Also pip is installed via brew, which pip returns /usr/local/bin/pip.
Actually, not quite brew install python would have installed pip because even doing brew search pip comes up with this warning.
If you meant "pip" precisely:
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.io/en/stable/installing/
So, Python came with pip, not brew install
when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OSX version of ipython?
There is no "OSX version of ipython"...
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python.
You actually did install them to your brew installed Python. IPython is not a new installation of Python.
You can even start a python interpreter from the terminal and import matplotlib to check this
I do not want to re-install everything again on the brew python
What exactly needs re-installed? It's already installed into the brew python
To transfer all your packages you can use pip to freeze all of your packages installed in ipython and then install them all easily from the file that you put them in.
pip freeze > requirements.txt
then to install them from the file pip install -r requirements.txt
I'm not entirely sure if I understood what you're asking so if this isn't what you want to do please tell me.
OK, so I solved by uninstalling macport (and so the ipython I was using, which was under /opt/local/bin) and installing ipython via pip. Then I re-install what I needed (e.g. jupyter) via pip.

Installing requests-kerberos on Windows

Is there any way to install requests-kerberos on Windows?
When I try to install it with pip I have the following error:
py -m pip install requests-kerberos
ImportError: No module named 'commands'
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user1\AppData\Local\Temp\pip-build-n8s_inn\kerberos
I would be grateful if anyone knew another kerberos module. I'm using Python 3.4 and Windows 8.
Best regards.
The commands module was deprecated in python 2.6.
Thus, the issue appears to be a problem with your pip installation, and not with requests-kerberos.
There are a few things you can try, but I would focus on ensuring pip is working correctly. While you could install the package manually, you are really just pushing the pip problem down the road until the next time you install a package.
Ensure pip is installed correctly.
Use the pip command to ensure you are running pip in the python 3.4 context: (Note, this is my output, yours will be different because you are on Windows and running 3.4)
$ pip --version
pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Additional information about pip can be found here.
Download and install manually
Download the package manually from the pypi repo.
Download the .tar.gz
Extract the tar.gz and run python setup.py install

Categories

Resources