My flake8 is giving different outputs to a colleague's, and the difference seems to be in the python version:
(hydro2) andrew#xxx $ flake8 --version
3.5.0 (mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 2.7.12 on Linux
Whereas on his machine it says CPython 3.5.0 or so.
I'm running the flake8 installed inside a python 3.5 virtualenv, and everything seems to point to the right place:
(hydro2) andrew#xxx $ which python
/home/andrew/virtualenvs/hydro2/bin/python
(hydro2) andrew#xxx $ python --version
Python 3.5.2
(hydro2) andrew#xxx $ which flake8
/home/andrew/virtualenvs/hydro2/bin/flake8
So I'm just confused as to why it's using CPython 2.7.12 (which is my OS's default) instead of the virtualenv's version?
I have tried uninstalling and reinstalling flake8 in the virtualenv.
To run a command line tool from a virtual environment you use python -m
Therefore, to run flake8 from your virtual environment:
python -m flake8
This assumes that you activated your virtual environment.
Related
I am trying to compile a code that works with Python 3.6. On my computer (Ubuntu 20.04), Python 2.7 and 3.8 comes pre-installed. Therefore, I manually installed python 3.6 using apt-get (I am not using any third party software e.g. Anaconda). I've also installed the development branch of 3.6 (something like libpython-dev).
However, when the code compiles, it needs to install certain packages (mpi4py, h5py etc) which should correspond/build with Python 3.6. However, the process detects Python version as 3.8. I have done the following in order to force the system to use 3.6 version:
In my bashrc file, I have created an alias for python (and python3) as python3.6
alias python='python3.6'
alias python3='python3.6'
The output of 'sudo update-alternatives --config python' is:
The output of commands python --version, python -V is Python 3.6.13. Therefore, I do not understand as to how to make the code works with 3.6. Please help!
You can install these packages using :
python3 -m pip install mpi4py(package_name) or
python3.6 -m pip install package_name
I installed python 3.8.5 with instructions from the docs.
Now my default python version is still 3.7.7
[agolys#linux ~]$ python --version
Python 3.7.7
But my python3 version is 3.8.5
[agolys#linux ~]$ python3 --version
Python 3.8.5
I tried to change it using alias, but it doesn't work:
[agolys#linux ~]$ alias python='/usr/bin/python3'
[agolys#linux ~]$ python --version
Python 3.7.7
Also PyCharm 'doesn't see' the 3.8 version, I can't make venv using it.
When I tried to make venv using python3 PyCharm is still showing "python 3.7"
Do you have any solution? I just need python 3.8 venv
EDIT: I use Fedora 31
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
I am trying to update from Python 2.7.17 to 3.8.1 so that I can run pip install pandas. I have installed pyenv, followed the instructions to add pyenv to my path, and installed 3.8.1. But every time I run python, it will not use version 3.8.1.
Running pyenv version returns 3.8.1, running python -V returns 2.7.17. Similarly, running python runs 2.7.17, and when I type python3 it runs Python 3.7.6?! But if I run pyenv global 3.7.6 the terminal tells me that 3.7.6 isn't installed!
I have also run pyenv global 3.8.1 in attempt to switch from 2.7.17 so 3.8.1, but still defaults to 2.7.17 when I type python.
I am using Ubuntu on Windows 10, if that helps.
Any help is greatly appreciated -- I am very very confused. Thanks in advance.
You could just use
pyenv shell 3.8.1
to set the PYENV_VERSION environment variable to the desired 3.8.1 version. But, I recommend you to use a virtual env:
pyenv virtualenv 3.8.1 my_test_env
and the activate it with:
pyenv activate my_test_env
For more info, this guide is super useful.
Several versions of python are installed on my Mac.
Usually, I am using Anaconda with Python 2.7. Nowadays I decide to try Python 3.6
Environment parameters:
which python
#/Users/User/anaconda/bin/python
which python3.6
#/usr/local/bin/python3.6
echo $PATH
/Users/User/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/User/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
The problem is:
~ User$ /usr/local/bin/python3.6 --version
Python 2.7.14 :: Anaconda, Inc.
How can I to overcome this trouble?
The output from the second command where running python3.6 --version prints out a Python 2.7.14 string doesn't make sense to me. You might try removing the Anaconda directories from your PATH environment variable and see if that resolves it.
The simplest way to manage and install multiple Python versions is through pyenv.
It allows you to install new versions with pyenv install <version> for dozens of Python versions including CPython as well as alternative interpreters like PyPy.
I would recommend you try installing pyenv:
$ brew install pyenv
Then install Python 3.6.5 via it:
$ pyenv install 3.6.5
You can set this version as your system-wide default Python version as well:
$ pyenv global 3.6.5
Then in projects where you want the python command to point to a Python 2.7 shim, you can set the local version in that directory with:
$ pyenv local 2.7.14
With these commands, you can just run python in any one of your project directories (after you've set a custom override version if desired), and not have to worry about calling python3.6 in some places, python2.7 in others, etc.
In a more advanced setup, you can also provide multiple Python versions if you have a project that needs both Python 2 and Python 3 together, for example, in a shell session:
$ pyenv shell 3.6.5 2.7.14
$ pyenv version
3.6.5 (set by PYENV_VERSION environment variable)
2.7.14 (set by PYENV_VERSION environment variable)
$ python --version
Python 3.6.5
$ python2 --version
Python 2.7.14
$ python3 --version
Python 3.6.5
(In this case whichever version you set first is the one that python points to by default.)