I was using Python 3.7 on my Mac (version 10.12.6), even though my default is python 2.7. None of my import statements were working (import cv2, import Pyautogui) when I looked back and realized that I had downloaded the packages to python2.7. how do I reinstall or move these packages to 3.7, I'm hoping to make python 3.7 my primary module. if I could make them automatically go to 3.7 that would be great as well. I am required to use '--user' for may of my PIP statements so I don't know if you can use two '--' statements together. Thanks.
If you have both Python 2 and Python 3 installed then you can access the PIP of Python 3 with the command python3 -m pip install SomePackage.
Please note, some packages might not be available for Python 3. Other packages might behave differently. Consider virtual environments like conda or venv for your work.
Related
I installed opensuse leap 42.3. Python 2.7.13 was also installed with it. I tried to install pandas and various other packages by
pip install pandas
It installed pandas for python 3.4 which is not installed in my system. So python programs with
import pandas
is not running with python 2.7
What should I do now ? Uninstalling python2.7 is not recommended as it came with os. If I install python 3.4, how should I avoid conflicts between two pythons while compiling any program.
Depending on your installation, you could try installing with pip2 instead of with pip.
This should specifiy that the installation refers to python 2.x, similar to how pip3 refers to python 3.x versions.
Thus use
pip2 install pandas
Using pip just defaults to one of these versions (most likely 3.x), which can result in unwanted behaviour. Although it is unlikely that this was the default if python 3.4 was not installed. Are you sure that this is the case?
This is mainly convention, so it is possible that it might not work on your device unfortunately.
To answer the second part of your question, conda is an excellent package manager/virtual environment that allow you to install and use as many different versions of python, with as many different packages as you want.
I am using a Python on a Mac and I know that Python 2 comes preinstalled on the system (and in fact usable through Terminal). Is there a way to make it so Terminal can run Python 3? Can/should you set this as a default? I know changing the default settings for Python version usage could break your system so should I just install Python 3 and then use it through its launch icon instead?
Use can use python version management tool
https://github.com/yyuu/pyenv
Package manager:
pip3 install something
Interpreter:
python3
You can use python 3 in terminal after you have python 3 installed. Every time you run a command type python3 instead of python if you are using pip to install modules you can do this:
But you must have pip installed for python 3
$ python3 -m pip install something
Best option is to install Python through Anaconda. This allows easy management and much more. You can have virtual environments having different Python versions as well as different modules installed.
as usual in Mac python 2.7 is already installed, however if you installed python 3+
then you can just type in terminal: python3
so that you can use the newer version that you installed.
if you want to use python 2.7 then just type: python
In the usr/bin folder, there are three versions of Pythons installed: Python, Python2.6, Python2.7 (the folder names) - not sure what version is for Python folder.
My issue, originally, was that I tried to install the module 'pandas' to run a script, python keeps telling me pandas could not be found.
'pip freeze' shows me pandas is already installed.
However, I could not find pandas using python>>help>>modules.
So I suspected there are multiple pythons installed causing pip installing for one of them, but the default python is a different one.
So my questions are -
1 Which python is the default one that comes with macOS Sierra? (I can confirm pandas currently is installed for Python, not Python2.6 or Python2.7)
2 Can I remove extra Pythons that do not have pandas?
3 How can I find what it the default Python when I type 'Python...' and how to install pandas for that python?
Solved:
Thanks for the comments and reply.
I used "python2.7 install pip" to install pip for python2.7. Then I used command 'pip2.7 install pandas'. This way, pandas is installed for the default python. (The command 'pip install pandas' on my machine, is installing for python 2.6.)
macOS Sierra uses Python 2.7 by default.
You can uninstall a version of Python as described here. However, you shouldn't need to as long as you are managing your packages and environments. If you want to maintain more control over your projects and their packages/versions, you should take a look at virtualenv. Virtualenv creates environments that have their own installation directories that don't share packages with other virtualenv environments. This is a very popular option many people use when managing projects.
You can use pip --version to see which version of Python you are installing a package for. You can also use pip list to see which packages are currently installed.
I highly recommend taking a look at virtualenv as it'll make keeping track of Python environments and their respective packages a lot easier.
Hope this helps!
I can download python 2.7.12 from python.org, and all python versions from 2.7.9 onwards are supposed to come with pip, but after installing it, using pip in the terminal does not work.
I am on macOS.
Have I installed pip, and if I have, how do I use it?
Here you have informations about pip:
https://packaging.python.org/installing/
normally python from python.org come with pip, maybe you should just update...
to update from terminal:
pip install -U pip setuptools
After when you need to install package, for example numpy, just do in a terminal:
pip install numpy
more informations here :
https://pip.pypa.io/en/stable/reference/pip_install/
you can also use conda install from anaconda as an alternative of pip :
http://conda.pydata.org/docs/get-started.html
Multiple instances of Python can coexist on your machine. Thus you could have installed Python 2.7.12 yet, when you call Python from terminal, you may be calling an older version.
To know which version you are using, type which python in terminal and look at its path. Then from Python in terminal, type
import sys
print(sys.version)
to get the exact version.
As Dadep says, I would recommend using conda to isolate your invironments if you have to play with multiple Python interpreters. Further conda simplifies 3rd party package installation process beyond doubt.
I'm not overly familiar with Linux and am trying to run a Python script that is dependent upon Python 3.4 as well as pymssql. Both Python 2.7 and 3.4 are installed (usr/local/lib/[PYTHON_VERSION_HERE]). pymssql is also installed, except it's installed in the Python 2.7 directory, not the 3.4 directory. When I run my Python script (python3 myscript.py), I get the following error:
File "myscript.py", line 2, in
import pymssql
ImportError: No module named 'pymssql'
My belief is that I need to install pymssql to the Python 3.4 folder, but that's my uneducated opinion. So my question is this:
How can I get my script to run using Python 3.4 as well as use the pymssql package (sorry, probably wrong term there)?
I've tried many different approaches, broken my Ubuntu install (and subsequently reimaged), and at this point don't know what to do. I am a relative novice, so some of the replies I've seen on the web say to use ENV and separate the versions are really far beyond the scope of my understanding. If I have to go that route, then I will, but if there is another (i.e. easier) way to go here, I'd really appreciate it, as this was supposed to just be a tiny thing I need to take care of but it's tied up 12 hours of my life thus far! Thank you in advance.
It is better if when you run python3.4 you can have modules for that version.
Another way to get the desire modules running is install pip for python 3.4
sudo apt-get install python3-pip
Then install the module you want
python3.4 -m pip install pymssql
The easiest way is to use virtual environments instead of system paths or environment scripts. See official Python package installation guide.
All you need to do is to
# Create fresh Python environemnt
virtualenv -p python3.4 my-venv
# Activate it in current shell
source my-venv/bin/activate
# Install packages
pip install mysqlclent
Note that mysqlclient is Python 3.x compatible version.