I have both python 2.7 and python 3.5.2 installed, both open IDLE just fine, my question is, if I go into the Cmd on Windows and type python it goes for the 2.7 version, how do I set it up so I have something like python2 and python3?
And finnally if i run python pip install package how do I know if it's installing for python 2.7 or 3.5.2.
You can use Python Launcher in Windows CMD.
Execute script:
py -2.7 path_to_my_script.py
or:
py -3.5 path_to_my_script.py
You can use pip the same way:
py -2.7 -m pip install numpy
for install NumPy in Python 2.7 or:
py -3.5 -m pip install numpy
for install NumPy in Python 3.5
Rather than using pip, use pip2 when targeting Python 2, and pip3 for Python 3.
Windows does have these pip2 and pip3 version-specialized commands.
If you already installed a package and want to know what Python version of the package you installed, run an interpreter and import it.
python2
>>> import package
ImportError: No module named 'package'
python3
>>> import package
>>>
Related
I installed Ubuntu 20.04, and python3 (3.8) is installed by default.
To install python3.9, I executed:
sudo apt install python3.9
Thus, I have two versions of Python at my laptop: 3.8 and 3.9.
I'm trying to launch the simple script:
import numpy
With Python 3.8 it works correctly. But, when I interp my script by Python 3.9 the error occurs:
How to solve this problem?
I've already tried to update numpy using pip, nothing has happened.
pip3 install numpy --upgrade
Likely what is happening here is, because you have 2 versions of python installed, your pip3 command is only installing things for one of the versions, 3.8 in this case.
Specifying the python version you want to run your command with will help solve this issue.
For example,
python3.9 -m pip install numpy
or
python3.8 -m pip install numpy
You can install a package for a specific version of Python with
python3.9 -m pip install numpy
For a more consistent python environment look at python venv or a container.
I am trying to update the module vpython to the most current version. I run:
pip3 install --user vpython --upgrade
in a Jupyter terminal. This gives the error:
ERROR: jupyter-server-proxy requires Python '>=3.5' but the running Python is 3.4.2
But when I run:
python3 --version
it returns:
Python 3.5.2 :: Anaconda 4.1.1 (64-bit)
Is there something going wrong with the installed Python3 kernel for Jupyter?
Change the environmental variable in your control panel just a simple conflict between python 3.4 and 3.5 this will surely solve your issue.
The issue is that you are using pip3 which is not always tied to the specified python you are trying to run. pip is a module installed with each python3 instance, so to specify it to install to a python environment, use the -m flag:
python -m pip install <module>
Where python is the python that you expect. For instance, if you want it to run against the installation that you use through python3, then you would do python3 -m pip install <module>. This makes things easy to track, since if you want to see which python you are installing to, you can use python -m pip -V. On my machine that outputs:
pip 19.3.1 from /Users/mm92400/anaconda3/lib/python3.6/site-packages/pip (python 3.6)
My Mac computer has Python 3.6 and Python 2.7 and I have successfully installed the basic modules such as numpy, scipy and matplotlib, for example, by doing the routine pip install and pip3 install. My Python 3.6 works totally well in Anaconda-Jupiter-Notebook, IDLE and Terminal, while Python 2.7 works only in terminal but not in IDLE.
Then for version check I tried
pip --version
Returning:
pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip (python 2.7)
pip3 --version
Returning:
pip 10.0.1 from /Users/son520804/anaconda3/lib/python3.6/site-packages/pip (python 3.6)
Then,
which python2
Returning:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
which pip2
Returning:
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip2
How could I resolve this issue and enable the Python 2.7 idle to import the modules? Much appreciated for your help.
find / -iname '*numpy*'
This is a terminal operation not a python command, you can try running that in the terminal to see where it's storing numpy, but you'll probably get the python3's version.
Try:
pip2 uninstall numpy
Then:
pip2 install numpy
It might be due to your machine seeing python3 as your default "python" so pip might actually be installing it again to python3. By denoting pip2 it should be linked to python2 (might actually need to do 'pip2.7'). Hope it helps!
Perhaps your pip is an alias to pip3. Find it out by pip --version and if so install packages for python 2.7 as pip2.7 install matplotlib
I'm working on mac OS X and I have both Python 2.7 and 3.3 on it. I want to install pykml module and i successfully installed it on python 3.3, but how do I do the same for Python 2.7?
You can do this if pip version >=1.5
$ pip2.6 install package
$ pip3.3 install package
if pip version is between 0.8 and 1.5 this will work
$ pip-2.7 install package
$ pip-3.3 install package
I am currently trying to install the PyDDE package.
Going to the command line and running pip install PyDDE initially didn't work, so I downloaded the zip package from https://github.com/hensing/PyDDE
and then I navigated to the unzipped folder and used the python setup.py command as specified in the installation instruction.
This installed the PyDDE module in python 2.7, and typing import PyDDE yields the module in 2.7. However, it does not install in 3.4.
I found this similar problem on stackoverflow (
Python 3.4 and 2.7: Cannot install numpy package for python 3.4
Installing numpy for Python 2.7 while also having Python 3.4 installed?
which provided solutions like using sudo pip and going to the python 3.4 folder and using easy_install PyDDE
Since it is already installed for python 2.7 when I use:
easy_install PyDDE or
pip install PyDDE
it happily tells me that pydde 0.2.2 is already installed/the active version, however, loading up Python 3.4 and importing PyDDE still doesn't work.
I have also tried python34 install PyDDE but python34 isn't a recognised command.
Any help would be appreciated.
You need to use pip3:
pip3 install PyDDE
pip installs python2 packages and pip3 does your python3 packages.
You need python3 in your pythonpath go to:
My Computer/Properties/Advanced System Settings/Environment Variables
And add C:\Python34\;C:\Python34\Scripts\ to your pythonpath.
Then download get-pip.py and run python34 get-pip.py