如何将 python 从 3.7 降级到 3.6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52584907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:08:14  来源:igfitidea点击:

How to downgrade python from 3.7 to 3.6

pythonpython-3.x

提问by Igor Kvasha

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.

我正在尝试安装 tensorflow,但它需要安装 Python 3.6,而我只安装了 Python 3.7。我尝试使用 brew 和 pyenv 进行切换,但它不起作用。

Does anyone know of a way to solve this problem?

有谁知道解决这个问题的方法?

回答by Jeereddy

$ 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

回答by Vijaya

If you are working with Anaconda, then

如果您正在使用 Anaconda,那么

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

might work.

可能工作。

回答by ersh

create a virtual environment, install then switch to python 3.6.5

创建一个虚拟环境,安装然后切换到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

当您想要使用 tensorflow 时激活环境

回答by Sidharth Taneja

Download python 3.6.0 from https://www.python.org/downloads/release/python-360/

https://www.python.org/downloads/release/python-360/下载 python 3.6.0

Install it as a normal package.

将其作为普通包安装。

Run cd /Library/Frameworks/Python.framework/Version

cd /Library/Frameworks/Python.framework/Version

Run lscommand and all installed Python versions will be visible here.

运行ls命令和所有已安装的 Python 版本将在此处可见。

Run sudo rm -rf 3.7

sudo rm -rf 3.7

Check the version now by python3 -Vand it will be 3.6 now.

现在检查版本,现在python3 -V是 3.6。

回答by Seyed Hamed Shams

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

使用conda创建python虚拟环境,然后安装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 activatethe environment whenever you want to use tensorflow.

从现在开始,您可以随时使用 tensorflow激活环境。

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

如果您没有 conda 包管理器,请先从这里下载:https: //www.anaconda.com/distribution

回答by nondeterministic

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:

一种无需卸载以前版本或恢复到其他软件(如 Anaconda 或 docker 等)的干净方法是下载 Python 3.6 源代码并按如下方式安装:

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

To use it you either:

要使用它,您可以:

  • add /home/<user>/python3.6/binto your PATH(and libto 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.

  • 添加/home/<user>/python3.6/bin到您的PATH(和libLD_LIBRARY_PATH)并完成它。(您可能还需要添加到包含路径等中,具体取决于您要实现的目标 - 但我希望您明白了。);

  • 或者,您可以创建一个类似的虚拟环境:/home/<user>/python3.6/bin/python3.6 -m venv env-python3.6

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

不需要 sudo 或 root 访问权限。不要搞乱你的系统。

回答by Mathew Paul

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

我在使用 python 3.7 安装 tensorflow 时遇到问题,并按照这些说明使用 python3.6 设置虚拟环境并使其正常工作

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

为tensorflow设置python3.6虚拟环境

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

如果您使用的是 jupyter notebook 或 jupyter lab,这有助于选择正确的虚拟环境

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.

此时,您可以启动 jupyter,创建一个新笔记本并选择位于您的环境中的内核。

virtual environment and jupyter notebooks

虚拟环境和 jupyter 笔记本

Hope this helps

希望这可以帮助