Is it possible to have pyenv switch between two system versions of Python? I have recently installed Ubuntu 14.04 on my laptop, and it comes shipped with both python2 (v2.7.6) and python3 (v3.4.0) commands. (And the command python links to python2).
After installing pyenv, and typing pyenv versions it shows only one entry with * system, which is apparently the python2 version..
Do I need to install Python3 with pyenv, in order for it to be able to switch between Python2 and Python3? (I hope it is not necessary since I already have it installed)
Note: I know that I could just type python3 prog.py to run Python3, or I could insert an alias python=python3 in my ~/.bashrc but this is not what I am looking for. I am more interested to have programs with the #! /usr/bin/env python shebang to run with the Python3 interpreter..
There is a plugin just for this case: pyenv-register.
Related
I recently installed python3.9.6 on kali linux and it all seemed to work but when enter python3 on the terminal it shows python3.9.2, not python3.9.6 .
Also when I type python its shows python 2.7.2 .
I want to type in python, python3, or python3.9 to open python3.9.6 can someone help me please change this?
Uninstall all the redundant versions of Python 3.x that you have, then reinstall the only one you want (e.g. python3.9.6).
In the latest version of Kali Linux, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python.
python-is-python3 (sudo apt install python-is-python3) is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3, but it does not add a symlink to point the /usr/bin/python2 interpreter (which is installed by the python-minimal package) at the current default python3. It may improve compatibility with other modern systems, while breaking some obsolete or third-party software.
python-is-python3 replaces: python, python-is-python2.
So I made a mistake and routed the python command to point to python 3.6.9 and now certain programs (namely ROS packages) are having issues. I'm on Ubuntu 18.04. I see lots of tutorials telling people how to alias python to python3 but not how to fix this issue. Also I tried to unalias python, but that did nothing.
So now when I run python --version OR python3 --version I see python 3.6.9
And when I run pip --version OR pip3 --version I see pip 20.1.1 from /home/me/.local/lib/python3.6/site-packages/pip (python 3.6)
You can install an isolated Python 2.7 in your system and actually have several versions of Python. One of the easiest ways is pyenv
You can do it like this:
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
Follow the instructions, you may need to reload your env (re-log in into the console).
Then install and set Python 2.7 as a default Python:
pyenv global 2.7.18
Somehow i have 2 versions of Python 2 installed. The one installed in usr/local/bin is Python 2.7.13 and the one in usr/bin is Python 2.7.6 - i want to keep the 2.6 version and remove the other one.
How do i remove the other one safely ?
Output of which python
/usr/local/bin/python
Also, the symlink points to python2.7 in the usr/local/bin itself.
EDIT: The other version is not 2.6 but 2.7.6, which should be the default version installed.
The default python version on your server is python2.7. If you remove it, you will break your system. Some apps use python2.7 to work.
If you really need to keep python2.6 (old python script for example), just specify the path to python2.6 when executing a script :
/usr/bin/python2.6 some_old_script.py
You can create virtualenv too :
virtualenv -p /usr/bin/python2.6 my_venv
cd my_venv
source bin/activate
Now your venv is active, if you run :
python some_old_script.py
The script will be run in python2.6
To exit the venv :
deactivate
EDIT
Using multiple python versions on the same system is not a problem. It's oftenly required (python2.6, 2.7, 3 etc.)
If by mistake you installed multiple python versions (in our case python2.7.6 and python2.7.13), you can use aliases to point to the version you want to use by default :
alias python=/your/python/path/python2.7.6
Using a Debian-based Linux distro (Kali) for Python programming (note that I am very new to Linux, had it for less than 2 months). Installed Python and GitKraken the usual way with apt-get install.
Started happily coding using the 3.5.3 IDLE, but when I tried to use pip commands to install modules (all of this as root user), I found it was installing to /usr/local/lib/python2.7/dist-packages rather than the Python 3.5.3 location (/usr/local/lib/python3.5/dist-packages).
When I used pip install module, it installed all modules to the 2.7 location. Because the Terminal used 2.7 by default (for whatever reason), using ./code.py always ran code using Python 2.7, but I wrote the code for Python 3.5 (not the version the modules were installed for).
I saw some other answers on this website for similar problems, where you have to install new modules and change the PYTHONPATH variable and assign aliases, but it messed more stuff up. Now echo $PYTHONPATH returns nothing, and pip still installs to the Python 2.7 location.
I used apt-get to install python-pip3 and I use the pip3 command to install modules, but whenever I use ./code.py (my main method to run code), it still uses Python 2.7. How can I change this?
Edit the shebang at the first line of code.py to point to your Python 3.5 binary, e.g.:
#!/usr/bin/env python3
Or if it's not linked as python3 figure out were your Python 3.5 binary is and use that.
I have a mac, when I do:
python --version
I got:
Python 2.7.6
but when I got to:
/System/Library/Frameworks/Python.framework/Versions/3.3
where is 2.7.6 located ?
any advice what should I do?
UPDATE:
$ which -a python python3
/usr/bin/python
/usr/local/bin/python3
$ brew list python python3
Error: No such keg: /usr/local/Cellar/python
$ locate python
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.
in PyCharm editor, the default settings interpreter shows:
You could have multiple Python versions on your macOS.
You may check that by command, type or which command, like:
which -a python python2 python2.7 python3 python3.6
Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:
compgen -c python
By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.
It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use apropos or locate python command to locate more Python related files.
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like brew list python python2 python3).
The locate database (/var/db/locate.database) does not exist.
Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
After the database is rebuild, you can use locate command.
To check third version, we can use,
python3 --version
To install python on macOS, we need to install command line developer tools. From Catalina, python is removed from OS bundle. For more information, Apple Official and Python Official.
Use below command to see all python installations :
which -a python
Use the which command. It will show you the path
which python
Take a look at the docs regarding Python on Mac.
The version at /System/Library/Frameworks/Python.framework is installed by Apple and is used by the system. It is version 3.3 in your case. You can access and use this Python interpreter, but you shouldn't try to remove it, and it may not be the one that comes up when you type "Python" in a terminal or click on an icon to launch it.
You must have installed another version of Python (2.7) on your own at some point, and now that is the one that is launched by default.
As other answers have pointed out, you can use the command which python on your terminal to find the path to this other installation.
You can use python official installer. It's very easy and interactive.
Refer https://www.python.org/downloads/release/python-2716/
Just type python and then hit tab-button You will get the list of all the python available in your os