I think I broke my pip after desperately trying to uninstall Python3.7. (I am on a Mac)
I removed the python folder from the application, removed /Library/Frameworks/Python.framework and removed the folders from /usr/local/bin according to https://osxuninstaller.com/uninstall-guides/properly-uninstall-python-mac/. I then installed python3.6.
src$ pip3.6 --version pip 9.0.1 from
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
(python 3.6)
but pip itself does no longer work.
src$ which pip
/usr/local/bin/pip
src$ pip --version
-bash: /Library/Frameworks/Python.framework/Versions/3.7/bin/pip: No such file or directory $
It still references the python 3.7 folder. How can I unlink that reference? THe same is btw. true for the package virtualenv that I installed. I can install it with pip3.6 but calling virtualenv still references to the framework folder of 3.7
You need to install pip in that environment. i.e 3.7.
Reason is when you deleted the default install you deleted the dependencies/ libraries that came with it.
Easiest way is to install python afresh via homebrew if you have it.
brew install python
Alternatively you can follow the instructions here to download a file to install pip securely. Homebrew can become messy when managing python environments. I'd recommend looking at something like anaconda if you are going to using different python versions with their own dependencies etc.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
Other options for fresh install are described in answer here. Hope that helps.
How do I install pip on macOS or OS X?
Related
I'm trying to upgrade Python 3.7 to 3.9 on macOS Big Sur. I'm also trying to avoid losing packages that were installed on Python 3.7 and reinstalling them again on Python 3.9
I tried using
brew install python3
brew update && brew upgrade python
which yielded
Already up-to-date.
Warning: python3 3.9.1_7 already installed
However when I run python3 --version it yields Python 3.7.0
Is this an issue with the alias? Is there a way to uninstall Python 3.7 and keep Python 3.9?
Running brew link python3 yields
Linking /usr/local/Cellar/python#3.9/3.9.1_7...
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3'
To force the link and overwrite all conflicting files:
brew link --overwrite python#3.9
To list all files that would be deleted:
brew link --overwrite --dry-run python#3.9
I fixed this frustrating error by first removing the Python 3.7 manually, by deleting it from the Applications folder and then uninstalling Python 3.9 using brew uninstall python3
Next, I downloaded and installed the latest Python from here and it worked!
To save all the installed packages by generating a requirements file, Run
python3 -m pip freeze > requirements.txt
and to install them in another environment, Run
python3 -m pip install -r requirements.txt
I suggest use official binaries:
Download version you need from the python.org
Call the .pkg
Invoke Update Shell Profile.command script under /Applications/Python\ 3.XX/
After all reboot your terminal
Check your Python version. The old version and dependencies remain intact.
I am trying to install jupyter on mac,
I understand that the mac comes with python version installed
But i also installed brew and installed python through brew.
When i check python location i get:
which python
/usr/bin/python
When i check pip location i get:
which pip
/usr/local/bin/pip
When i try to install jupyter:
pip install install
after a long installation it tried to remove python package that it want's to upgrade
And fails:
On trying to uninstall dateutil.
I think its the mac packages.
I tried with sudo, no change.
As far as i can understand it because the files are immutable.
Tried to remove the immutable with:
chflags uchg.
No change.
I also tried to work with virtual env, using:
sudo pip install virtualenvwrapper.
But that pip tries to uninstall another python folder.
Any suggestions?
Thanks
UPDATE:
The brew seems to create links from python2. to python2
And the same for python3.
I tried to create the link myself, It worked and i was manage to install the package i wanted. But its not a good solution,
The all point of brew is to manage this things for me, next time i will upgrade python it will break.
Any suggestions why? could it be because the brew installed two python version on my laptop?
RESOLVED:
Found the answer, thanks to #tdube question i went and looked what brew guys did to python and found this thread from Jan 17.
I turns out that they changed the behavior or installing python.
No you don't have simply python any more.
You have python2 and python3.
No more simply pip, now you have pip2 and pip3.
That is a major change from the default behavior of how people use python
Especially that mac comes with a default python
so now you have
python that is /usr/bin/python
python2 that is /usr/local/bin/python2
python3 that is /usr/local/bin/python3
this is the fix, the brew guys suggest ( you can see it when running brew info python ):
==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.zshrc:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Pip and setuptools have been installed. To update them
pip2 install --upgrade pip setuptools
You can install Python packages with
pip2 install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: http://docs.brew.sh/Homebrew-and-Python.html
You can read about it in this thread:
The Python that comes "pre-installed" on Mac is located in /usr/bin/python. I think you need to change the order of the entries in your PATH environment variable as noted here (python homebrew by default). Which file your PATH is set in depends on which shell you are using.
I used pyenv, pyenv-virtualenv for managing python virtual environment.
I have a project working in Python 3.4 virtual environment.
So all installed packages(pandas, numpy etc) are not newest version.
What I want to do is to upgrade Python version from 3.4 to 3.6 as well as upgrade other package version to higher one.
How can I do this easily?
Here is how you can switch to 3.9.0 for a given virtual environement venv-name:
pip freeze > requirements-lock.txt
pyenv virtualenv-delete venv-name
pyenv virtualenv 3.9.0 venv-name
pip install -r requirements-lock.txt
Once everything works correctly you can safely remove the temporary requirements lock file:
rm requirements-lock.txt
Note that using pip freeze > requirements.txt is usually not a good idea as this file is often used to handle your package requirements (not necessarily pip freeze output). It's better to use a different (temporary) file just to be sure.
Use pip freeze > requirements.txt to save a list of installed packages.
Create a new venv with python 3.6.
Install saved packages with pip install -r requirements.txt. When pip founds an universal wheel in its cache it installs the package from the cache. Other packages will be downloaded, cached, built and installed.
OP asked to upgrade the packages alongside Python. No other answers address the upgrade of packages. Lock files are not the answer here.
Save your packages to a requirements file without the version.
pip freeze | cut -d"=" -f1 > requirements-to-upgrade.txt
Delete your environment, create a new one with the upgraded Python version, then install the requirements file.
pyenv virtualenv-delete venv-name
pyenv virtualenv 3.6.8 venv-name
pip install -r requirements-to-upgrade.txt
The dependency resolver in pip should try to find the latest package. This assumes you have the upgrade Python version installed (e.g., pyenv install 3.6.8).
If you use anaconda, just type
conda install python==$pythonversion$
What happened:
After an OSx update and installing a new version of python 2.7 my virtualevn environment completely broke and I struggled in fixing it. I wasn't sure what caused it and went through a whole set of things that I did and read initially that didn't work are listed below. What solved my problem is provided in the answer section.
What didn't work to fix virtualenv command not found:
Installed python through homebrew and then used pip to install virtualenv
Installed python through https://www.python.org and then used pip to install virtualenv
Related questions that helped me but did not provide the solution to my problem:
virtualenv-command-not-found
virtualenv-workon-command-not-found
Complete manual recovery I went through (What not to do!):
This didn't completely solved my problem. It is just to give you an idea of what steps I went through before I found the correct way to fix my python dev environment on my OSx.
Removed python 2.7 by using the post in here
Removed the homebrew installed version
Installed python through the pkg file in Mac OS X 32-bit i386/PPC installer or Mac OS X 64-bit/32-bit installer
Manually installed virtualenv following the instructions from here:
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz
tar xvfz virtualenv-13.1.2.tar.gz
cd virtualenv-13.1.2
sudo python setup.py install
Manaully install pip through 7:
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
PIP was still broken after all this:
After all this after creating a virtual environment my pip still installed the packages in the main python folder instead of installing them under the virtual environment and non of the threads here neither here helped. My solution to that was to run pip under my virtual env with the following options:
1- Activate the virtual environment so that $VIRTUAL_ENV is set:
source venv/bin/activate
2- Forces pip to install in the right destination:
pip install --target=$VIRTUAL_ENV/lib/python2.7/site-packages
Summary
Something was badly broken and best way I fix my dev environment is provided in the answer to this question.
The reason
In my case was an OSx upgrade that affected my homebrew and after upgrading to python 2.7.11 is didn't install it properly.
How I got it to work:
I found steps 3 and 4 in a thread here and many thanks to https://github.com/baronomasia.
1 - Removed python 2.7 by using the post in here
2 - Removed the homebrew python installed version
brew uninstall python
3- Reinstall your Xcode command tools:
sudo xcode-select --install
4- Upgrade homebrew and reinstall python through homebrew:
brew update && brew reinstall python
After doing brew upgrade python my system python was broken and was throwing fits about virtualenvwrapper.sh, as well as my pip command was just suddenly missing.
I went to python.org and downloaded the python 2.7.13 installer, ran it, I now have python 2.7.13, pip, and can run pip install virtualenvwrapper and things seem to work.
I am on shared hosting and I need to install pip with the correct python version, 2.7. To install pip, I did:
$ easy_install pip
However, after it was installed I get the following:
[dave#web1 lib]$ pip --version
pip 1.0.2 from /home/premiere/dave/financials/lib/pip-1.0.2-py2.7.egg (python 2.4)
How would I re-install pip to work on the python2.7 version, which is also installed on the machine?
[premiered#web1 ~]$ python --version
Python 2.6.6
Which is strange, since it is installing to python2.4.
You may want to create a virtualenv using -p /path/to/python-2.7.binary param, and then activate it. Then all stuff you installed using pip would be correctly into your virtualenv.
If multiple versions of python are installed on the system, then you should invoke the version you want when installing. i.e.
$ python27 easy_install pip
This creates a pip file in your path that contains the specified version of python in the hashBang line.