I recently tried to uninstall Python 3.5.2 and installed Python 3.6.0. I used to use python in the command line to run Python 3.5.2 from the command line, and py to run Python 2.7.12. Now, python runs Python 3.5.2, and py runs Python 3.6.0. I am running Windows 10, and python3, python2, py2, and py3 do not do anything.
Don't bother adding Python to the path. Just use:
py Run highest version of Python (override with PY_PTYHON environment variable).
py -2 Run highest version of Python 2.
py -3 Run highest verssion of Python 3.
py -2.7 Run Python 2.7.
py -2.7-32 Run python 2.7 32-bit when on a 64-bit system.
More: https://docs.python.org/3.6/using/windows.html#python-launcher-for-windows
Note you can also specify in scripts which version to use as well with, for example:
#!python2
#!python3
#!python2.7
Related
I'm using Python 3.6 installed with pyenv and apt-get. In the shell if I do python3 --version it shows
python3 --version
Python 3.6.0
I'm using Ubuntu 20.04 ARM version, and it comes with Python 3.8 installed. However, when running a test command, it's invoking /usr/bin/python3 which is Python 3.8. I'm getting the following error:
import pexpect
/usr/local/lib/python3.8/dist-packages/pexpect/__init__.py:75: in <module>
from .pty_spawn import spawn, spawnu
/usr/local/lib/python3.8/dist-packages/pexpect/pty_spawn.py:14: in <module>
from .spawnbase import SpawnBase
E File "/usr/local/lib/python3.8/dist-packages/pexpect/spawnbase.py", line 224
E def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
E ^
E SyntaxError: invalid syntax
Under the hood, it's still using Python 3.8. How can I fix that?
** Update ** Since Python 3.7 async is a reserved keyword.
I'm using Ubuntu 14.04 and recently I have installed Python 3.7 instead the default 2.7
I have also updated the alias to version 3.7, however; when I install new packages that require 3.6 and later, it shows me that python (2.7 detected). Below, I attach an example for the issue showing that installing NetworkX version 2.5 (which requires 3.6 and later python versions) cannot achieved due to the detection of python 2.7
Proof of Python 3.7 is working
mininet#mininet-vm:~$ python
Python 3.7.0 (default, Jun 28 2018, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[7]+ Stopped python3.7
Example of how python 3.7 cannot be detected
mininet#mininet-vm:~$ pip install networkx
Downloading/unpacking networkx
Downloading networkx-2.5.tar.gz (1.5MB): 1.5MB downloaded
Running setup.py (path:/tmp/pip_build_mininet/networkx/setup.py) egg_info for package networkx
NetworkX 2.5+ requires Python 3.6 or later (2.7 detected).
For Python 2.7, please install version 2.2 using:
$ pip install 'networkx==2.2'
Complete output from command python setup.py egg_info:
NetworkX 2.5+ requires Python 3.6 or later (2.7 detected).
For Python 2.7, please install version 2.2 using:
$ pip install 'networkx==2.2'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_mininet/networkx
Storing debug log for failure in /home/mininet/.pip/pip.log
Any solution/suggestion will be highly appreciated,
When you install another version of python on top of another, the path of the new python and pip are added to the PATH. This can create some collisions.
So when you type pip you call the python 2 pip because this is the first match in your PATH.
But why it works with the interpreter?
Python 2 only has the py keyword to invoke the interpreter, python 3 has both command py and python. Thats why you can bypass the collision.
How to resolve collisions?
If you don't plan to use python 2, you can remove the PATH of the python interpreter and pip for python 2. Or you can use pip3 to invoke pip for python 3.
A better workaround to avoid python collisions and by extend packages collisions, you can check virtual environments.
I have uninstalled python completed from my windows 10 and even deleted all its path from environment variables but it is runnning python -V and showing Python 2.7.14 which was never there.
I want to remove this 2.7.14 but it is not present anywhere on my system.
When i run python in command line it gives ImportError: No module named site which is OK(since i have uninstalled python).
But after running python --version it shows Python 2.7.14 which was never there in the first place. the only python i had was python 3.7.6 which i have installed.
python on cmd gives
ImportError: No module named site
while
python -V gives
Python 2.7.14
Open a command prompt and type where python.exe:
C:\Users\partner>where notepad.exe
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
If it is in your path this should find it for you.
I already installed the latest version of Python 3 and I installed Pygame using the terminal I also included import Pygame in my file however when I run the file it refuses to open and displays the error message "no module named pygame"
What's the problem?
What's the solution?
Try python3 first.py in your terminal.
Or in your file first.py add this line at the top:
(I used python3.x but you should add the correct version of your python 3)
#!/usr/local/bin/python3.x
To see your version:
$ python3 -V
Python 3.5.2
To see your python 3 path:
$ which python3
My system: Mac OS X 10.6.8, gcc 4.2, python 2.7, xcode 3.2.3
I use python 2.7 and I got error when tried to do: import objc, it returns: ImportError: No module named objc.
It looks like the objc module is not there. But actually I have the objc module installed already. Snow Leopard has got pyobjc preinstalled and I have also checked this using python2.6 (I have python 2.7 and 2.6 in my Mac). So if I invoke import objc using python2.6, I got no error which means objc exists and I can use that module without problems ... but if I import using python 2.7, I will got the ImportError: No module named objc error.
Does anyone have any solution? FYI, the python2.6 is coming preinstalled with OS X while 2.7 is manually installed. I've been using the 2.7 for couple of months without problems.
Python C extension modules like objc cannot be re-used between python versions. You'll have to install the objc module for 2.7 separately.
Generally, different python installations (such as 2.6 or 2.7, or 3.2) use separate module import locations, and you normally install extensions per python setup.
In general, packages installed with one python installation are not available to other python installations. You can make them available by messing with sys.path (or by setting PYTHONPATH in your environment) and installing your modules to a common place, however, as pointed out by #MartijnPieters, if it is a C extension, you'll need to re-build the module for python 2.7 (and then you can't put it in a common place). Usually, this is as easy as:
<sudo> python2.6 setup.py install #install for python 2.6
<sudo> python2.7 setup.py install #install for python 2.7
since the command python is generally just a (soft) link to your preferred python installation.
sudo may or may not be necessary depending on where your python implementations live on your path.
This works for pure python modules too by the way. Since the source code generally doesn't take up too much space, this may be a good way to install all your modules if you'll be switching back and forth between python 2.6 and python 2.7.
The same thing goes if you're using easy_install to install your packages:
easy_install-2.6 somepackage
easy_install-2.7 somepackage