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
Related
I am currently running python 3.9.13 on my mac. I wanted to update my version to 3.10.10
I tried running
brew install python
However it says that "python 3.10.10 is already installed"!
When i run
python3 --version
in the terminal it says that i am still on "python 3.9.13"
So my question is, how do i change the python version from 3.9.13 to 3.10.10? I already deleted python 3.9 from my applications and python 3.10 is the only one that is still there.
I also tried to install python 3.10.10 from the website and installing it. However it does not work. Python 3.10.10 is being installed successfully but the version is still the same when i check it.
Python 3.10.10 is already installed along with Python 3.9.13. Your path is probably pointing to 3.9.13 and that's why you're getting that Python version.
Try modifying your path variable to point to brew's Python installation, or (better yet) make use of a virtual environment.
a) Telling what Python version your PATH variable is pointing to:
$ which python
Will tell you what's the actual executable's path. That way, you are going to see exactly where you main python resides.
b) If you want to create a virtual environment with brew's python try something like:
$ /usr/local/Cellar/python#3.10/3.10.1/bin/python3 -m venv py310
$ source venv/bin/activate
$ python
> # you should be inside a 3.10.1 envornamente
> CTRL+D
$ pip install requests
you can use pyenv to work with multiple python environments
things to do:
install pyenv : brew install pyenv
install particular python: pyenv install 3.10.10
set python3.10.10 to gloabal python env: pyenv global 3.10.10
and can start using python 3.10.10 version
Just delete the current python installation on your device and download the version you want from the offical website. That is the easiest way and the most suitable one for a beginner.
I want to use brew to install pre-commit for python 3.6.8. I am using macOS Catalina (Version 10.15.7)
I am using brew install pre-commit to do the installation.
I am having issues because my pre-commit uses Python 3.9 and I want to avoid this (i.e. make brew pre-commit use python 3.6).
When I try brew install pre-commit, I find that automatically one sees the message Downloading https://homebrew.bintray.com/bottles/python%403.9-3.9.0_2.catalina.bottle.tar.gz.
The environment that I am on is python 3.6.8. ( python -V returns python 3.6.8).
Also,
username#USERNAME-M-F1AU % echo "$PATH"
/Users/username/.pyenv/shims:/Users/username/.pyenv/shims:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I also have, python 3.9 (python#3.9), (although it is not the active environment) in /usr/local/Cellar. I also have a folder for pre-commit inside /usr/local/Cellar. Some paths inside subfolders which are inside /usr/local/Cellar/pre-commit are linked to python 3.9. Following are examples of the same.
python3 -> ../../../../../opt/python#3.9/Frameworks/Python.framework/Versions/3.9/bin/python3.9
python -> ../../../../../opt/python#3.9/Frameworks/Python.framework/Versions/3.9/bin/python3.9
The first line of /usr/local/bin/pre-commit is:
#!/usr/local/Cellar/pre-commit/2.9.0/libexec/bin/python
I have tried the following already:
Change of Python environment to Python 3.6. Issue was not solved here (symlinks of pre-commit with python 3.9)
Deletion of cache (rm -r /Users/username/.cache/pre-commit). Same thing happened here (symlinks of pre-commit with python 3.9 still existed).
Installing of precommit again (rm -r /usr/local/Cellar/pre-commit followed by brew install pre-commit). Same thing happened here (symlinks of pre-commit with python 3.9).
Removing and readjusting symlinks using the method shown below.
ln -nfs /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/local/Cellar/pre-commit/2.9.0/libexec/bin/python
ln -nfs /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/local/Cellar/pre-commit/2.9.0/libexec/bin/python3
Here, I got the following error /usr/local/Cellar/pre-commit/2.9.0/libexec/bin/python3: No module named pre_commit
What is the best way in which I can use brew to install pre-commit such that it uses python 3.6 and not python 3.9?
I saw this brew precommit page. It looks like brew install pre-commit automatically always uses python 3.9.0.
Any help will be appreciated.
brew only really works with the latest versions of software -- they package bottles against the latest version of python
you can pin against older formulas, though at this point the 3.6 packages no longer cleanly build (I tried, as a way to show you how to do this, but they've bitrotted)
since it looks like you're using pyenv -- probably your best bet is to install a python3.6 using that and then use pip to install pre-commit from there
I don't use pyenv myself, but if I recall correctly you'd run:
pyenv install 3.6.12
pyenv global 3.6.12
and then you would use python3.6 -m pip install pre-commit --user (you may need to add the --user bin directory to your PATH using your .bashrc / .zshrc)
disclaimer: I'm the creator of pre-commit and I've contributed a bit to the brew formula for it
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 run python 3.7 in Ubuntu 18.04 terminal with "python3" command but python3 is running python 3.6
If you're having to juggle between too many versions, try pyenv to manage multiple versions easily. Here's a script that makes installation easier
If you have Python 3.7 installed, then you may create symlink to it:
ln -s python3.7 python3
Check your python versions with which python in your terminal.
After which, if python 3.7 is not installed. Follow the steps listed here to install it.
You can then follow the answer here to change the symbolic link
How can I use python 2.7 for some apps, while keeping python 2.6 for the OS?
I am using CentOS6.6 (based on RHEL 6 / Fedora 12), and would like to install some recent packages such as meld 3.13, latest rabbitcvs, etc...
It requires python 2.6 to run.
when I try to run meld 3.13, it says "Meld requires Python 2.7 or higher."
I have successively installed python 2.7 following this tutorial
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
how can I tell meld to use python2.7 ?
The best way to install python 2.7 on CentOS 6 for some apps only without touching the default system provided python 2.6 is to use Software Collections.
Check page of software collection python27, it provides description how to install it and link to the package.
It works like this: the collection installs packages into separate directory tree in /opt/rh/python27 and doesn't have any effect until it is enabled.
In your case you can create wrapper script which will run your version of meld with python27 collection. For example save following script into ~/bin/meld:
#!/bin/bash
COMMAND="/path/to/your/meld $#"
scl enable python27 "$COMMAND"
Then every time you run meld command, it would be executed by python2.7 (assuming your meld is not already available in your PATH).
See more details in Packaging Wrappers for Software Collections (while you are not packaging anything, the tip with wrapper seems to be useful in your case).
virtualenv is a tool to create isolated Python environments.
For example:
$ python --version # 2.7.6
$ sudo pip install virtualenv
$ mkdir myproject
$ cd myproject
$ virtualenv -p /usr/bin/python3.4 myenv # assign python version
$ . myenv/bin/activate
(myenv)$ python --version # 3.4.3
Now you can use python 3.4 in the virtual environment.
To quit:
$ deactivate