Different python versions both os and pycharm - python

I am running on Ubuntu 18.04 and using Pycharm 2020.1. My system using Python version 3.7.6 and Pycharm using 3.6. And this makes conflicts.
$ python --version
Python 3.7.6
$ ls /usr/bin/python*
/usr/bin/python /usr/bin/python2.7 /usr/bin/python3.6 /usr/bin/python3m
/usr/bin/python2 /usr/bin/python3 /usr/bin/python3.6m
I tried to change python interpreter but not showing in the list. What can I do for using same version both os and pycharm?

You need to choose System Interpreter option not Virtual Environment.
However, is highly not recommended.

Related

Python Multiple version installation in Linux rocky

I am new to Python and Linux env, so a little confused.
I want to find where my Python3.9 is installed, so that I can update the PATH..
Running python --version or python3 --version give me Python 3.6.8
I want to install Python 3.9, so when I run sudo dnf install -y python39 it gives me
Package python39-3.9.12-1ep1.el8.x86_64 is already installed.
ls /usr/bin/python* doesn't show 3.9
Output of above command - /usr/bin/python /usr/bin/python3 /usr/bin/python3.6
/usr/bin/python3.6m
Also tried alternatives --config python but it shows only 3.6
-----------------------------------------------
* 1 /usr/libexec/no-python
+ 2 /usr/bin/python3
which python3.6 gives /usr/bin/python3.6
which python3.9 gives /usr/bin/which: no python3.9 in....
rpm -ql python39-3.9.12-1ep1.el8.x86_64 gives me
/etc/gdbinit.d/python39.gdb. /opt/python3.9.
/opt/python3.9/bin
I could be missing something obvious, if someone can point me in the right direction it will be awesome.
what happens when you enter the following command: python3 --version and is it any different compared to running python --version?
I am not sure what is your actual requirement is. But if you have already installed python 3.9 in your machine, then you can have this and all previous versions applied to different projects. This is selected when you create virtual environments. For example if you want to run a project that built on 3.6, then you can select python interpreter 3.6 at the time of creation.
So the virtual machine I was working was built using vagrant, it had python 3.6 in usr/bin and python 3.9 in opt/python3.9. Newbie like me who wanna understand what /opt is - https://www.baeldung.com/linux/opt-directory
To search any package used command - rpm -ql python39-3.9.12-1ep1.el8.x86_64
Once package is found add it to path as symlinking binaries can be confusing
vim ~/.bashrc
PATH=/opt/python3.9/bin

PyCharm doesn't list python3.6

My PyCharm doesn't list the latest interpreter when choosing the location of the interpreter in the preferences.
version: PyCharm 2018.1
operating system: Linux Mint 19 Cinnamon
$ ls /usr/bin/python3*
/usr/bin/python3 /usr/bin/python3.5m /usr/bin/python3.6-config /usr/bin/python3.6-dbg-config /usr/bin/python3.6dm-config /usr/bin/python3.6m-config /usr/bin/python3-dbg /usr/bin/python3dm /usr/bin/python3m
/usr/bin/python3.5 /usr/bin/python3.6 /usr/bin/python3.6-dbg /usr/bin/python3.6dm /usr/bin/python3.6m /usr/bin/python3-config /usr/bin/python3-dbg-config /usr/bin/python3dm-config /usr/bin/python3m-config
However, in the preferences of PyCharm, python3.6 is not selectable:
When I try to select python3 from the list it still uses python3.5 even though python3 is a symbolic link to python3.6:
$ readlink -f /usr/bin/python3
/usr/bin/python3.6
In PyCharm, I still get:
>> import sys
>> print(sys.version)
3.5.2 (default, Jan 10 2018, 06:17:28)
I am configuring the [Default Settings...] and also the project settings under [Settings...]
If it is not appearing in pycharm then you can add the path. Go to Settings>Project interpreter>Virtualenv Environment>...>add. Then make sure you path to python 3.6. Also do the same thing for System interpreter. Hope that helps
Updating PyCharm might do the trick.
The Software Manager of Linux Mint currently only offers PyCharm 2018.1, but you can get a newer version by following the instruction from the official website.
Installing the latest version of PyCharm using snap might help.
$ sudo apt install snapd
$ sudo snap install pycharm-community --classic
I had the exact same issue with the Community version where I couldn't add virtual environments based on other versions of Python than 2, 3, and 3.8.
Upgrading to the Professional version magically solved the problem for me.

pyenv installs multiple pythons, but recognizes only some

I am trying to get pyenv up and running (Mac OS X), so I can use tox/detox to test code vs. multiple python environments. I was able to install multiple python3 versions, and then I used pyenv global on all the versions. After doing that, pyenv versions returns this list:
system
* 3.2.6 (set by /Users/Workspace/.pyenv/version)
3.3.6
3.4.6
3.5.3
3.6.1
However, only 3.4 and 3.5 are recognized (along with 2.7.8, which I believe is 'system'):
Geoffreys-MBP:pydnmr-tox Workspace$ python --version
Python 2.7.8
Geoffreys-MBP:pydnmr-tox Workspace$ python3.2 --version
-bash: python3.2: command not found
Geoffreys-MBP:pydnmr-tox Workspace$ python3.3 --version
-bash: python3.3: command not found
Geoffreys-MBP:pydnmr-tox Workspace$ python3.4 --version
Python 3.4.3
Geoffreys-MBP:pydnmr-tox Workspace$ python3.5 --version
Python 3.5.2
Geoffreys-MBP:pydnmr-tox Workspace$ python3.6 --version
-bash: python3.6: command not found
Any ideas what is causing this behavior? tox/detox similarly cannot find any Python version besides 3.4/3.5.
Edit: it seems that pyenv has installed all the environments, but python3.x commands weren't finding them. python3.4 and python3.5 were working because they found previous top-level installations. Results for pyenv which python3.x.y vs. python3.x [--version] shown below.
$ pyenv which python3.2
/Users/Workspace/.pyenv/versions/3.2.6/bin/python3.2
$ python3.2 --version
-bash: python3.2: command not found
$ python3.2
-bash: python3.2: command not found
pyenv which python3.3
/Users/Workspace/.pyenv/versions/3.3.6/bin/python3.3
$ python3.3 --version
-bash: python3.3: command not found
$ pyenv which python3.4
/usr/local/bin/python3.4 # old install
$ python3.4 --version
Python 3.4.3 # not 3.4.6 installed by pyenv
$ pyenv which python3.4.6
pyenv: python3.4.6: command not found
$ python3.4.6 --version
-bash: python3.4.6: command not found
$ pyenv which python3.5
/Users/Workspace/.pyenv/versions/3.5.3/bin/python3.5
$ python3.5 --version
Python 3.5.2 #Linked to my old 3.5.2 install instead of pyenv 3.5.3 install
$ pyenv which python3.6
/Users/Workspace/.pyenv/versions/3.6.1/bin/python3.6
$ python3.6 --version
-bash: python3.6: command not found
However, installing tox-pyenv as suggested in the answers below allowed tox to find and use all of these environments!
pyenv interpreter discovery is not integrated with tox core (yet). So everything that work is just because tox happens to find some with the unaware discovery methods it already applies.
There are two ways to make this work consistently:
Tell pyenv about all your interpreters in the context where you call tox. e.g. in the project where you want to run tox pyenv local system 3.2.6 3.3.6 3.4.6 3.5.3 3.6.1 Then tox should find all of them. If you want this to be the default wherever you are you cant set pyenv global exactly like that. The first in the list is the interpreter that is invoked, when just calling python, but all others should also be active and therefore discoverable for tox.
If this doesn't do it for you for whatever reason or you like it to be a bit more automatic: there is a plugin - tox-pyenv that takes care of the discovery
You can set all the versions you need by using pyenv global. For example:
pyenv global 3.6.0 3.5.3 3.4.6 2.7.10
I use this approach for my libraries and tox runs without any issue :)

ImportError: No module named psutil while using robotframework

I'm using robotframework for automation. I'm trying to use a method from my python library which needs psutil. The problem is when I execute from the robotframwork it gives error ImportError: No module named psutil but when I execute it with Pycharm I don't get any error. I have installed psutil using pip install psutil . I searched a lot on web but couldn't find any reason for this issue.
My experience with this error was that I had multiple versions of python installed on my ubuntu server 16.04LTS.
My PATH resolved to /usr/local/python -> python 2.7.10 meaning typing python into the commandline I got 2.7.10, but the standard path /usr/bin/python linked to python 2.7.12. The psutil module and others were only installed for version 2.7.10
My resolution was to re-symlink /usr/bin/python to point to my 2.7.10 version:
# Find which python your PATH is pointing at and the version
$ which python
# Returns
/usr/local/bin/python
$ /usr/local/bin/python --version
# Returns
Python 2.7.10
$ /usr/bin/python --version
# Returns
Python 2.7.12
Unlink and relink to correct python version in /usr/bin/python
$ cd /usr/bin
$ sudo unlink python
$ sudo ln -s /usr/local/bin/python python
# check python version points correctly
$ /usr/bin/python --version
# Now correctly returns
Python 2.7.10
P.s. Bear in mind it's still worth checking all your modules are correctly installed now that your environment is pointing at the 1 python version
Could you try setting the PYTHONPATH in your environment or by passing it as an option.
This person had a different issue, but the fix I think will be the same:
setup pythonpath before starting test suite
Cheers,
K

Mac OSX: Switch to Python 2.7.3

I've installed the Mac OSX Python 2.7.3, and tried switching to the new version:
$ python2.7 -V
Python 2.7.3 # It was installed
$ python -V
Python 2.6.1 # Default is 2.6
$ export VERSIONER_PYTHON_VERSION=2.5
$ python -V
Python 2.5.4 # I can switch to 2.5
$ export VERSIONER_PYTHON_VERSION=2.6
$ python -V
Python 2.6.1 # And 2.6
But:
$ export VERSIONER_PYTHON_VERSION=2.7
$ python -V
python: VERSIONER_PYTHON_VERSION environment variable error (ignored)
Python 2.6.1
Can't switch to 2.7! Why is that?
The python.org install will put a python executable in /usr/local/bin . Apple's python is in /usr/bin
To call the python.org python you can use its full path /usr/local/bin/python or change your path to put /usr/local/bin before /usr/bin. You will still be able to call Apple's python by using its full path /usr/bin/python
Some python installs e.g. Macports provide a tool that provides symbolic links to various python installs and allows you to switch between them.
I don't think we can switch the python version on the Mac OS X without resorting to something like MacPorts or ActivePython.
I think it's because VERSIONER_PYTHON_VERSION is specific to python packages built by apple.

Categories