How to downgrade python from 3.7 to 3.6

2020-02-02 06:25发布

I'm trying to install tensorflow but it needs a Python 3.6 installation and I only have Python 3.7 installed. I tried to switch using brew and pyenv but it doesn't work.

Does anyone know of a way to solve this problem?

7条回答
Bombasti
2楼-- · 2020-02-02 07:03

I was having trouble installing tensorflow with python 3.7 and followed these instructions to have a virtual environment setup with python3.6 and got it working

Download the Python3.6 tgz file from the official website (eg. Python-3.6.6.tgz)
Unpack it with tar -xvzf Python-3.6.6.tgz
cd Python-3.6.6
run ./configure
run make altinstall to install it (install vs altinstall explanation here 

setting up python3.6 virtual environment for tensorflow

If you are using jupyter notebook or jupyter lab this can be helpful to choose the right virtual environment

python -m venv projectname
source projectname/bin/activate
pip install ipykernel
ipython kernel install --user --name=projectname

At this point, you can start jupyter, create a new notebook and select the kernel that lives inside your environment.

virtual environment and jupyter notebooks

Hope this helps

查看更多
不美不萌又怎样
3楼-- · 2020-02-02 07:03

Create a python virtual environment using conda, and then install the tensorflow:

$ conda create -n [environment-name] python=3.6
# it may ask for installing python-3.6 if you don't have it already. Type "y" to proceed...
$ activate [environment-name]
$ pip install tensorflow

From now on, you can activate the environment whenever you want to use tensorflow.

If you don't have the conda package manager, first download it from here: https://www.anaconda.com/distribution

查看更多
▲ chillily
4楼-- · 2020-02-02 07:06

create a virtual environment, install then switch to python 3.6.5

$ conda create -n tensorflow python=3.7
$ conda activate tensorflow
$ conda install python=3.6.5
$ pip install tensorflow

activate the environment when you would want to use tensorflow

查看更多
不美不萌又怎样
5楼-- · 2020-02-02 07:09
$ brew unlink python
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
$ brew switch python 3.6.5
$ pip install tensorflow
查看更多
爱情/是我丢掉的垃圾
6楼-- · 2020-02-02 07:12

If you are working with Anaconda, then

conda install python=3.5.0
# or maybe 
conda install python=2.7.8
# or whatever you want....

might work.

查看更多
该账号已被封号
7楼-- · 2020-02-02 07:15

A clean way without having to uninstall a previous version or reverting to additional software like Anaconda or docker, etc. is to download the Python 3.6 source code and install it as follows:

$ mkdir /home/<user>/python3.6
$ ./configure --prefix=/home/<user>/python3.6/
$ make altinstall

To use it you either:

  • add /home/<user>/python3.6/bin to your PATH (and lib to LD_LIBRARY_PATH) and be done with it. (You may also need to add to your include path etc., depending on what you're trying to achieve exactly - but you get the idea, I hope.);

  • or, you create a virtual environment similar to this: /home/<user>/python3.6/bin/python3.6 -m venv env-python3.6.

No sudo or root access required. No messing up your system.

查看更多
登录 后发表回答