My Mac (which I am just starting to use for a development machine to stretch my wings a little from the Windows world) has 2 system-installed versions of Python (python25-apple and python26-apple) as well as 2.7 which I installed and want to use.
I have successfully run port select python python27 and when I list the versions, python27 shows as active and when I run python --version I get 2.7.3.
I'm now trying to install oauth2 using either easy_install or pip. Having run the appropriately labeled setuptools.egg file: setuptools-0.6c11-py2.7.egg (for example as noted at https://stackoverflow.com/a/5792150/8151) in my shell, I expected to have easy_install point at the correct python version, but when I run either easy_install pip -n or easy_install oauth2 -n`, both are using the 2.6 versions of the file, for for some reason the setup tools does not seem to have updated easy_install to the 2.7 version. Or at least that's what I think seems to be wrong. In addition, there's now an easy_install-2.6 in my path, so it would seem as though easy_install is pointed at the correct version, but it still always tried to install the 2.6 versions of pip or oauth2.
Did I miss a step in here somewhere, or is there another way to do what I need to do?
EDIT
I should probably note that I installed python from MacPorts.
The best way to be sure is to use the specific commands for the version you want, e.g: easy_install-2.7, pip-2.7, etc...
Related
I cannot for the life of me get VS Code to run Python 3. I've installed Python 3 and followed several VS Code tutorials to get it set up. I've set the user settings to point to my install of Python 3: "python.pythonPath": "/usr/local/bin/python3"
However, every time I run python in the terminal within VSC, it is Python 2.7. When I try to install anything using pip, I get warnings that 2.7 will no longer be supported etc.
As an example, when I try to install something with pip, I get the following error:
ERROR: Could not install packages due to an EnvironmentError: [Errno
13] Permission denied:
'/Library/Python/2.7/site-packages/urllib3-1.25.3.dist-info' Consider
using the --user option or check the permissions.
Any ideas? It's driving me crazy that I simply can't get VSC to switch to Python 3.
Mac has python version 2 set as default and usually does not come with pip preinstalled or is linked with version 2. I recommend leaving it that way. Use version 3 for your personal use cases and leave your Mac with version 2 as default. As you have to install python3 yourself, means you might also want to check/install pip3.
Check if you have python 3 installed:
python3 --version
Check if you have pip3 installed (usually included by default since python 3.4):
pip3 --version
Set VS Code to use Python3 on the bottom right corner, which you should see when having a .py file open:
And now if you want to import any modules into python, make sure to install them with pip3:
pip3 install package_name
If you run into permission issue again, you might consider to run the command with sudo rights:
sudo pip3 install package_name
Try using pip3 install instead of pip install, pip is most likely linked against pip2.
I had the same error (ArchLinux), and VS Code also worked with Python 2 by default
You need to go into VS Code -> File -> Preferences -> Settings -> Extensions -> Python. Then find the configuration of the Python Path, and instead of Python, specify Python3, or, as in my case, Python3.8.
configuration of the Python Path
After that, I switched from the Python 2 version to Python 3, but the error remained. So I took advantage of this article and turned off pylint
https://code.visualstudio.com/docs/python/linting
python2.7 was the first widely stable version of python and came pre-installed on unix like OS such as Mac and Linux after it's acceptance. Many python apps have been built on python2.7 although python2.7 has been discontinued. However, it is still maintained with bug fixes. Most applications and OS that support python usually default to python2.7 that usually gets invoked using python. to use python version 3, append 3 to python (python3). python3 libraries and plugins are mostly differentiated from default python with an appendage of 3 to the library name or plugin name such pip3. As a result you have both versions of python live on your system without conflicts. Note that you cannot port python 2.7 codes to python3
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.
I have the requests module installed on my system.
pip install requests
Now I am trying to import requests in the rpel
import requests
It fails with the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
The most common reason for this is that you have two versions of Python 2.x, and the pip that comes first in your PATH doesn't go with the python that comes first in your PATH.
There are two ways that can happen.
First, you may have, e.g., /usr/local/bin before /usr/bin on your PATH, but your /usr/local copy of Python doesn't have pip. So, when you run pip install requests, that's /usr/bin/pip, which installs into /usr/lib/python2.7/site-packages. But when you run python, that's /usr/local/bin/python, which looks in /usr/local/lib/python2.7/site-packages.
Second, even though your two Python 2.x's are in different locations, they may want to install pip (and other scripts and executables) to the same place. In particular, /usr/bin is usually reserved for stuff that comes with the OS or its package manager, so if you use /usr/bin/python ez_setup.py or /usr/bin/easy_install pip or many other common ways to install pip, it may end up in /usr/local/bin. In which case it will overwrite any earlier /usr/local/bin/pip that went with your /usr/local/bin/python. At any rate, the result is basically the same: pip now means /usr/local/bin/pip, but it still goes with your /usr Python, not your /usr/local Python, and installs into /usr/lib/python2.7/site-packages, which /usr/local/bin/python can't see.
If your two versions are, e.g., 2.7 and 3.4, there's no problem; per PEP 394, either the 3.x versions of everything have to be run with python3 and pip3 and so on, or the 2.x versions have to be run with python2 and pip2 and so on.
If your two versions are, e.g., 2.6 and 2.7, there is a problem, but you can easily work around it, because you should always have pip2.6 and python2.6 vs. pip2.7 and python2.7. You can confuse yourself with python and pip, but you don't have to.
If your two versions are both 2.7, however, there's no way to disambiguate (except by using complete absolute paths all the time, which no one wants to do).
So, why would anyone ever install two copies of Python 2 without knowing what they're doing?
The most common reason is that they're on a Mac, which comes with Python 2.7, but they read a blog post that told them to install another Python and didn't explain how to know what they're doing. Apple's pre-installed Python is in /usr/bin but installs scripts and binaries to /usr/local/bin. The most popular alternative Python versions are the python.org installer and Homebrew, both of which install to /usr/local/bin by default. The fact that Mac users tend to be less Unix-savvy than Linux or FreeBSD users probably doesn't help, but even without that, this is a perfect way to end up with thousands of people who have a pip and a python that doesn't match, and no idea why.
There used to be good reasons for almost all Mac Python users to installing a second Python. Until OS X 10.6, Apple's pre-installed Python versions tended to be badly out of date, and sometimes broken. If Apple's only giving you 2.4, it makes sense to install 2.6. And doing so is no problem, because python2.4 and python2.6 are easy to disambiguate. But Apple has been installing a working 2.7 for years now. There are sometimes good reasons why you need a different one (you need a bug fix in 2.7.7 but Apple gave you 2.7.5, you need a 32-bit build, you need an extra-batteries version like Enthought, you need to build py2app bundles out of it, …), but these reasons do not apply to most people anymore.
In fact, many people on StackOverflow seem to have three versions of Python 2.7. I'm not sure why this is so common, but they'll use Homebrew to install Python 2.7, and then use an installer from Python.org or Enthought, and now they've got three Python 2.7 versions all fighting over ownership of /usr/local/bin.
So, how can you fix this?
If you can use Python 3.x, install that and just use pip3 and python3 (and ipython3 and so on), and paths aren't an issue anymore.
If you don't need a second Python 2.7, get rid of the non-Apple one and just use Apple's.
Otherwise, do not ever use Apple's Python, do not install things for it, do not touch it; just leave it alone for Apple's own tools. If you use Homebrew, its Python should be higher on the PATH (make sure you've got /usr/local/bin before /usr/bin), and it should let you pip install foo without sudo, while Apple's won't, which makes it hard to accidentally screw up and install to the wrong one.
I've also seen at least one Windows user who had both C:\Python27 and D:\Python27, both on the PATH, with the C: one first, but pip only installed for D:. This seems to be far less common than the Mac confusion (probably because Windows doesn't come with Python, and there are no package managers, so the only way you're going to get any Python is by running an installer). And the solution is even simpler here: Windows doesn't need Python, so you can delete whichever one you want.
Finally, on non-Mac *nix systems, especially RHEL/CentOS Linux, you may have a Python 2.6 or 2.4 that's needed by the OS plus a Python 2.7 that you installed because you needed it, or a 2.7 that's needed by the OS and a 2.5 installed as a dependency for some "compatibility" package, or similar. Either way, you can easily accidentally install the pip for the one you don't actually use (especially if you install it with the pip bootstrap instead of your package manager).
The solution here is pretty simple: uninstall that pip, and use yum or apt or whatever to install the python-pip that goes with the Python 2.7 you want to use. And get in the habit of using python2.7 and pip2.7—or just add aliases to your profile so that python or py or whatever you prefer runs python2.7.
For devs with similar problem: Intall python3 version directly from the pack file on their website.
DO NOT DELETE OR EDIT ANYTHING ON usr/local/bin !
rm -rf /Library/Frameworks/Python.framework/Versions/2.7
rm -rf "/Applications/Python 2.7"
Install python3 directly from package on official website.
Reopen VSCode, (if you don't use it, you must) re-install modules in "Not Found" state, run command:
pip3 install requests
and other "not found" modules by command pip3 install xxxxxx
Add "python.pythonPath": "/usr/local/bin/python3" to your settings.json file.
pip install request
-bash: pip: command not found
or
no module name requests
how to fix errors
first:
Download the following and install with python http://get-pip.py
https://bootstrap.pypa.io/get-pip.py
[go to the link and download the python script that I provided and then run it or right click and save as]
then after running script "python space (drag and drop the script in terminal)" run "pip install requests" if you get the error below;
-bash: pip: command not found
See the path mentioned in the warning.
then follow this steps acordilly
see the path in yellow?yeah
/Users/macbookair/Library/... etc
type cd in terminal and then drag and drop the bin folder
1.cd /Users/macbookair/Library/Python/2.7/bin {cd /Users/name/path/Python/version/bin )
./pip install requests
after theses steps
Now run your python script again it should work
up vote me if it helped you.
Are you using Linux and have both python2 and python3 installed?
If so, you installation by:
pip install requests
would install the module to python2
So if you run import in python3, it may cause the problem.
Try to call:
pip3 install requests
to install the module in python3 environment.
I am currently trying to run Pydev with Pymongo on an Python3.3 Interpreter.
My problem is, I am not able to get it working :-/
First of all I installed Eclipse with Pydev.
Afterwards I tried installing pip to download my Pymongo-Module.
Problem is: it always installs pip for the default 2.7 Version.
I read that you shouldn't change the default system Interpreter (running on Lubuntu 13.04 32-Bit) so I tried to install a second Python3.3 and run it in an virtual environement, but I can't find any detailed Information on how to use everything on my specific problem.
Maybe there is someone out there, that uses a similar configuration and can help me out to get everything running (in a simple way) ?
Thanks in advance,
Eric
You can install packages for a specific version of Python, all you need to do is specify the version of Python you want use from the command-line; e.g. Python2.7 or Python3.
Examples
Python3 pip your_package
Python3 easy_install your_package.
Over the past couple of months I've set about using Wing IDE to do the vast majority of my programming. I chose Wing primarily because it works well with wxPython, allowing me to debug much more quickly than was the case when I was using TextWrangler alongside Terminal. A quirk of Wing however is that there is no satisfactory way to force universal builds of python to run in 32-bit mode. Since I'm using wxPython 2.8.x (32-bit only) I'm using a 32-bit-only version of python as the executable (2.7.1). So long as I'm only using the python standard library and wxPython I have no problems, my trouble begins when I start trying to install third-party modules to work with this 32-bit version of Python. I want to do all my installing using macports, but it appears that the macports I have downloaded installs modules for use only with a different version of python that happens to be universal. Essentially then this is a question about macports, and I'd appreciate clarification on the following two points:
If I want three versions of python on my computer (say 2.6, 2.7 and 3.2), and want to use macports to install modules for each of them, do I need three separate versions of macports - one for each python?
If I'm right about (1) how do I set about installing separate versions? I've looked on the macports website but can find no reference to alternative versions based on which version of python you want to use it with
Help much appreciated.
A Python installed at /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 almost certainly has nothing to do with MacPorts. You probably installed it from a python.org installer. If you want to install packages to it, you should install separate versions of easy_install using the Distribute package and/or pip for it and directly install packages for that Python instance with them. Those versions will be installed in the framework bin directory, /Library/Frameworks/Python.framework/Versions/2.7/bin. You can't manage Python packages for it from MacPorts; that works only for MacPorts Pythons, i.e. at /opt/local/bin.
So it appears you have three versions of Python 2.7 installed. The Apple-supplied system Python at /usr/bin/python2.7, a MacPorts-installed version at /opt/local/bin/python2.7, and a third (possibly from python.org) at /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 (for which there is likely a symlink at /usr/local/bin/python2.7). There's nothing inherently wrong about having all three installed and the three can easily co-exist. Just keep in mind which one you are using, either by managing your shell path or using an absolute path to each, and that any additional packages installed need to be installed to the correct Python's site-packages directory. If you use easy_install or pip, you need to install and/or use the correct one for each.
If your goal is just to use wx-python with Python 2.7, there is an outstanding MacPorts issue about building a 32-bit-only version of wx-python because of its dependency on deprecated OS X Carbon APIs. There appears to be a new MacPorts port of a Cocoa version of wxWidgets which should work in 64-bit mode. You might want to experiment with it:
sudo port selfupdate
sudo port install py27-wxpython-devel
No you don't need separate versions of macport, what you need is separate versions of python.
Clear steps to do it :
Install macports. You should be able to use port command after that. You should have /opt/local/bin first in your path automatically, if you are using the installer for Mac.
Install python 2.6 - sudo port install python26
Install python 2.7 - sudo port install python27
You can use python26 through /opt/local/bin/python2.6
You can use python27 through /opt/local/bin/python2.7
If you want to use the python27 as default then do a sudo port python-select python27. This will ensure that /opt/local/bin/python is linked to /opt/local/bin/python2.7.
Mac comes with default python installation which is not removed. It can be accessed from /usr/bin/python.
Macports installs it's tools under path /opt/local and binaries at /opt/local/bin. So now you will have multiple versions of python and located at different location so that you can choose which one to run.
The packages installed with a particular version of python will go in it's site-packages and will not be available to other versions of python installation.
[Edit: based on comments]
I have multiple versions of standard python installation.
~ $ /usr/bin/python
python python2.5 python2.6 pythonw pythonw2.6
python-config python2.5-config python2.6-config pythonw2.5
With python2.5, I get:
>>> print platform.architecture()
('32bit', '')
>>> sys.maxint > 2**32
False
With python2.6, I get:
>>> print platform.architecture()
('64bit', '')
>>> sys.maxint > 2**32
True
See the note at - http://docs.python.org/library/platform.html