一台计算机上的两个版本的python

问题描述:

我的计算机中装有Pyhton 3.8(32位),我使用Pycharm和jupyter笔记本. 我需要安装Python 3.6(64位),因为我需要使用tensorflow,并且仅适用于Python 3.6(64位)

I have Pyhton 3.8 (32-bit) in my computer, I use Pycharm and also jupyter notebook. I need to install Python 3.6 (64-bit) because I need to work with tensorflow and it only works with Python 3.6(64-bit)

我可以同时拥有两个版本的python吗?以及如何更改和使用pycharm和jupyter中的两个python版本?

Can I have two versions of python together? And How can change and work with two python versions in pycharm and jupyter?

现在使用python虚拟环境的首选方法是 venv .

The preferred way to use python virtual environments now is venv.

您可以在Windows上安装任意数量的python版本,但也请安装其附带的py启动器.这样一来,您就可以通过命令行轻松启动所需的任何python版本,而无需依赖PATH废话.

You can install any number of python versions on your windows, though please also install the py launcher that it comes with. This makes it easy to launch whichever python version you want through the commandline, with no need to rely on PATH nonsense.

如果您具有py启动器,则可以使用-

If you've the py launcher you can simply launch your desired python version using-

py -3.6-64

以上将启动python 3.6(如果已安装)的64位版本.

The above will launch the 64 bit version of python 3.6 (if installed).

现在,您还需要使用虚拟环境,并将pycharm指向venv.要创建venv,请转到您的项目目录(最好)并执行-

Now, you'll also want to use a virtual env and point pycharm to the venv. To make a venv, go to your project directory (preferably) and do-

> py -3.6-64 -m venv name_of_venv

这将在您的项目目录中创建一个名为name_of_venv的venv,而python版本将是3.6 64位.

This will make a venv named of name_of_venv in your project directory and the python version will be 3.6 64 bit.

现在,每当需要执行任何python命令时,就不再需要执行py -version,只需执行python甚至使用pip-但在此之前,您需要激活venv

Now whenever you need to do any python commands, you no longer need to do py -version, you can just do python and even use pip - BUT before that, you need to activate the venv

> & '.\name_of_venv\Scripts\Activate.ps1'

现在,您可以在此venv内执行常规的python操作,并且全部目标是3.6 64位(或您选择用来构建venv的任何其他版本).

Now you can do normal python operations as long within this venv and it'll all target 3.6 64 bit (or any other version you choose to build the venv with).

要取消激活(尽管您不必这样做)-您只需在终端中键入deactivate.

To deactivate (though you don't really have to) - you can just type deactivate in the terminal.

Pycharm可以使用此venv进行配置,就像指向它一样简单.您只需转到添加python解释器,然后选择 Virtualenv Environment

Pycharm can be configured with this venv as simply as just pointing to it. You simply have to go to Add python interpreter and choose Virtualenv Environment