I ned to install spyder for python 3.4.
I used this link
with the following code
Requirements:
sudo apt-get install python-qt4 python-sphinx
Installing:
sudo pip install spyder
Updating:
sudo pip install -U spyder
But when I run spyder it opens python 2.7
Since the only one that shows the number of python is the first one, I guess the issue is related with sphinx (but don't know).
How can I link spyder to python 3.4 instead of 2.7?
Install with pip3 instead of pip. It may be beneficial to work in an isolated python 3 environment such as a venv, remember the system python is python 2. Have a look at the Dockerfile I use to set up my environment to see if that helps.
Using pip3's full path when calling it will also probably help. I'm on my phone rather than laptop so can't confirm right now.
Related
I recently installed Python 3 and when I wanted to check the version, it says it is Python 2.7
As I understand it, the new MacOS comes with Python 2.7 so that seems to not be the issue.
So when I want to install pip it keeps saying
command not found
How do I install pip then? Help me please
Try the following command:
pip3 install package-name
If you still get the same error message, refer to the following link to get detailed instructions on pip installation on macOS:
https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
I had almost the same problem, what I did was to install Homebrew first.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
then add it to the path
after that you can install Python 3 by typing the following command :
$ brew install python
to check if Python3 has been installed type :
$ python3 --version
I would get in the habit of using a virtual environment for every project. Treat the stock system installations as an implementation detail of the OS, not something you should be modifying directly.
You can start with something as simple as
# Ignore the system-installed Python 2
python3 -mvenv venv
. venv/bin/activate
Now python and pip will each refer to the correct versions found in the virtual environment.
Today I faced a problem regarding pip3 in Ubuntu. Ubuntu comes with python 3.8 but I wanted to use latest versions of python, like 3.9 or maybe 3.10. So I installed it using 'ppa:deadsnakes' repository and also installed pip. But the problem is I want to use pip in python 3.9 instead of version 3.8. So I changed the default python version to 3.9 and everything crashed.
So reverted to python 3.8. Whenever I install some package it gets installed using python 3.8.
Help me, how can I use python 3.9 pip and install packages in python 3.9 without changing the default version.
Any help is appreciated.
--> Thing I want is that when I want to install python package using
pip3 install <package_name> it must install in python3.9 and not in python3.8
You don't need to install pip separately
You should be able to refer to it as such
python3.9 -m pip install
Hello everyone I fixed my issue.
The problem is we cannot override default python version in Ubuntu as so many things depend on it.
So I just made an alias as : alias pip3='python3.9 -m pip' and alias for python : alias python3='/usr/bin/python3.9'
If anyone face this issue please do what I specify and you will be good to go.
Now all my packages are being installed in python3.9.
Currently all python3 versions are using the same pip version which can be installed by:
sudo apt-get install python3-pip
The easiest way to work with a specific python version is creating a virtualenv and working under it. When working with a virtualenv you can use pip freely without worrying about which python version it belongs.
you can use pip for python3.9 by pip3.9 install <package-name>
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 am using Windows 10. Currently, I have Python 2.7 installed. I would like to install Python 3.5 as well. However, if I have both 2.7 and 3.5 installed, when I run pip, how do I get the direct the package to be installed to the desired Python version?
You will have to use the absolute path of pip.
E.g: if I installed python 3 to C:\python35, I would use:
C:\> python35\Scripts\pip.exe install packagename
Or if you're on linux, use pip3 install packagename
If you don't specify a full path, it will use whichever pip is in your path.
Because usually i change my intepreter to run something(i got 2 diff projects with both 2 and 3), i use these solution:
Add path to the environment as usual (of course)
Rename ur python.exe , in my case i want to run python 3 using command python3 on my cmd. So i renamed my python.exe in python3.x directory with python3. Itll works with python 2 ofc.
Then to use pip in both python, i use this command.
python3 -m pip install 'somepackage'
and to run pip on python2
python -m pip install 'somepackage'
This is may not the best solution out there, but i like this one
** WINDOWS **
ref : https://datascience.com.co/how-to-install-python-2-7-and-3-6-in-windows-10-add-python-path-281e7eae62a
In my case, I have Python 2.7 and Python 3.4, with the Python Launcher for Windows.
This is the output when running this commands:
PS C:\> pip -V
pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)
PS C:\> pip3 -V
pip 9.0.1 from C:\Python34\lib\site-packages (python 3.4)
I'll note that in my Python27\Scripts\ directory, I have pip.exe, pip2.exe and pip2.7.exe.
And in my Python34\Scripts\ directory, I have pip.exe, pip3.exe and pip3.4.exe.
So all of these .exe files help you when you have different versions of Python installed at the same time.
Of course, for this to work, you have to have the respective Scriptsdirectries in your Path system enviroment variable.
The answer from Farhan.K will work. However, I think a more convenient way would be to rename python35\Scripts\pip.exe to python35\Scripts\pip3.exe assuming python 3 is installed in C:\python35.
After renaming, you can use pip3 when installing packages to python v3 and pip when installing packages to python v2. Without the renaming, your computer will use whichever pip is in your path.
I would advise against ever calling any pip script directly (nor pip3, pip2.7.exe, anything like that).
Instead, a surefire way is to always prefer the explicit variant of calling pip's executable module for a specific Python interpreter:
path/to/pythonX.Y -m pip somecommand
path/to/venv/bin/python -m pip somecommand
C:\path\to\venv\Scripts\python.exe -m pip somecommand
There are many advantages to this, for example:
It is explicit for which Python interpreter the projects will be pip-installed (Python 2 or 3, inside the virtual environment or not, etc.)
For a virtual environment, one can pip-install (or do other things) without activating it: path/to/venv/bin/python -m pip install SomeProject
Under Windows this is the only way to safely upgrade pip itself path\to\venv\Scripts\python.exe -m pip install --upgrade pip
But yes, if all is perfectly setup, then python3 -m pip install SomeProject and pip3 install SomeProject should do the exact same thing, but there are way too many cases where there is an issue with the setup and things don't work as expected and users get confused (as shown by the many questions about this topic on this platform).
References
Brett Cannon's article "Why you should use python -m pip"
pip's documentation section on "Upgrading pip"
venv's documentation section on "Creating virtual environments": "You don’t specifically need to activate an environment [...]"
I ran across an issue with running pip with absolute path. This might be related to WinPython's installation routine and the order of installing Python 3.6 first, 2.7 second, or Python 3.6 being in the path.
No matter which pip was called, it was activating the 3.6 one:
λ C:\prog\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\Scripts\pip2.exe --version
pip 9.0.1 from C:\prog\WinPython-64bit-3.6.1.0Zero\python-3.6.1.amd64\lib\site-packages (python 3.6)
What finally did the trick was calling pip as a module of the respective python binary:
λ C:\prog\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python.exe -m pip --version
pip 9.0.1 from C:\prog\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\lib\site-packages (python 2.7)
Hope that might help someone with similar issues.
I tried many things , then finally
pip3 install --upgrade pip worked for me as i was facing this issue since i had both python3 and python2.7 installed on my system.
mind the pip3 in the beginning and pip in the end.
And yes you do have to run in admin mode the command prompt and make sure if the path is set properly.
1-open command prompt and change direction using the command cd C:\Python35\Scripts
2- write the command pip3 install --upgrade pip
3- close the command prompt and reopen it again to return to the default direction and use the command pip3.exe install package_name to install any package you want
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.