简体   繁体   English

如何在 iPython 中选择 Python 3.7 或 Python 3.8?

[英]How can I select Python 3.7 or Python 3.8 in iPython?

My OS is Windows 7我的操作系统是Windows 7

I need to use TensorFlow with Keras in Python , but it doesn't work yet in Python 3.8 .我需要在Python中将TensorFlowKeras一起使用,但它在Python 3.8 中尚无法使用。 So I've installed again Python 3.7 and his packages.所以我再次安装了Python 3.7和他的软件包。

Inside the IDE PyCharm was easy.在 IDE PyCharm内部很容易。 It just add another interpreter in settings and it works.它只是在设置中添加另一个解释器,它就可以工作了。 So when I create a project I need to select the right interpreter.所以当我创建一个项目时,我需要选择正确的解释器。

I also use iPython to make small tests.我还使用iPython进行小测试。 I've searched in all Stackoverflow and I don't find any answer that works in 2020. I use iPython and not the Jupyter environment.我在所有Stackoverflow 中都进行了搜索,但没有找到任何适用于 2020 年的答案。我使用的是iPython而不是Jupyter环境。

First, I've created the kernels, as iPython instructions said in its site.首先,我已经创建了内核,正如 iPython 说明在其站点中所说的那样。

python -m ipykernel install --user

It creates a json file in c:\\Users\\myname\\AppData\\Roaming\\jupyter\\kernels它在c:\\Users\\myname\\AppData\\Roaming\\jupyter\\kernels创建一个json文件

After I use iPython -h and he told me to use kernel subcommand:在我使用iPython -h ,他告诉我使用内核子命令:

Subcommands are launched as `ipython cmd [args]`. For information on using
subcommand 'cmd', do: `ipython cmd -h`.

Feeling more motivated, I've tried the command iPython kernel -h .感觉更有动力,我尝试了命令iPython kernel -h But I've got a very confusing text.但我有一个非常混乱的文本。

So I've tried to use the kernel option,所以我尝试使用kernel选项,

C:> iPython kernel

It gave me the following message:它给了我以下消息:

To connect another client to this kernel, use:
    --existing kernel-3404.json

However, I'm not getting select the right kernel.但是,我没有选择正确的内核。

I try to use use my kernel file, but with no success.我尝试使用我的内核文件,但没有成功。

Invalid argument: '--kernel.json'

So I'm lost, because in no place I've found a detailed instructions for kernel subcommand in line command options for iPython .所以我迷路了,因为我在iPython 的行命令选项中找不到内核子命令的详细说明。

I've found a solution that solves my problem in Windows 7. I don't even need ipyKernet package.我在 Windows 7 中找到了解决我的问题的解决方案。我什至不需要ipyKernet包。

I've started locating iPython.exe files in Python 3.7 and Python 3.8我已经开始在Python 3.7Python 3.8 中定位iPython.exe文件

c:\Users\myname\AppData\Local\Programs\Python\Python37\Scripts\ipython.exe 
c:\Users\myname\AppData\Local\Programs\Python\Python38\Scripts\ipython.exe 

So I've made the following script py.BAT and stored it in a folder inside the PATH environment variable (One can edit the PATH variable using Control Panel , Systems , Advanced system settings , environment variables ):因此,我制作了以下脚本py.BAT并将其存储在 PATH 环境变量内的文件夹中(可以使用Control PanelSystemsAdvanced system settingsenvironment variables编辑 PATH environment variables ):

@echo off
cd\dropbox\python
if "%1"=="37" goto ip37
if "%1"=="38" goto ip38
if not "%1"== "" goto erro
:ip38
  c:\Users\myname\AppData\Local\Programs\Python\Python38\Scripts\ipython
  goto fim
:ip37
  c:\Users\myname\AppData\Local\Programs\Python\Python37\Scripts\ipython
  goto fim
:erro
  echo Syntax: py 37   - iPython 3.7 
  echo         py 38   - iPython 3.8
  echo         py      - iPython 3.8
:fim

Now it's a piece of cake:现在是小菜一碟:

If I want to run iPython over Python 3.7如果我想通过Python 3.7运行iPython

py 37

If I what to run iPython over Python 3.8如果我在Python 3.8上运行iPython

py  

or或者

py 38

Of course I've checked Python version in each iPython session:当然,我已经在每个iPython会话中检查了 Python 版本:

import sys
print(sys.version)

The messages was消息是

3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]

or或者

3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30)[MSC v.1916 64 bit (AMD64)]

Any other param任何其他参数

py 40 # e.g.

results in结果是

Syntax: py 37   - iPython 3.7
        py 38   - iPython 3.8
        py      - iPython 3.8

Internal references in Python don't use PATH environment variables in general, but when one uses an utility in the shell as pip , has a problem because if you write pip in the shell, it searchs the first executable in the order of the string content in the PATH variable, generally the last Python version. Python 中的内部引用一般不使用PATH环境变量,但是当在 shell 中使用一个实用程序作为pip ,就会出现问题,因为如果在 shell 中编写pip ,它会按照字符串内容的顺序搜索第一个可执行文件在PATH变量中,通常是最后一个Python版本。

So one has to make a copy in the old Python version that utility in the same folder (please not rename the original file) with another name (Eg: pip.exe to pi.exe )因此,必须在旧的Python版本中使用另一个名称(例如: pip.exepi.exe )在同一文件夹中复制该实用程序(请不要重命名原始文件)

Other solution would be temporarily change the path environment variable inside PY.BAT and any other, if necessary.如有必要,其他解决方案是临时更改PY.BAT和任何其他内部的路径环境变量。 I haven't done it yet because everything is fine so far.我还没有这样做,因为到目前为止一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的 Ubuntu python3.7 升级到 python3.8 最新版本? - How I can upgrade my Ubuntu python3.7 to python3.8 latest version? 如何在 Python 3.8 上安装 PyQt5-tools(我只能看到最高 3.7 的版本) - How to install PyQt5-tools on Python 3.8 (I can see only wersion for up to 3.7) Python 3.7 & 3.8 和 VSCode - Python 3.7 & 3.8 and VSCode 我在 python 3.8 中有一个模块,但要在 3.7 中使用它 - I have a module in python 3.8 but to use it in 3.7 如何在 python 3.5、3.6、3.7 上对 pathlib 进行猴子补丁,以获得与 python 3.8 中相同的功能? - how can I monkey-patch pathlib on python 3.5, 3.6, 3.7 to get same functionality like in python 3.8? 我如何使用 python 3.8 下载 tensorflow - how can i download tensorflow with python 3.8 如何在 Python3.7/3.8 中使用泛型命名元组? - How to use generic namedtuple in Python3.7/3.8? 在 Windows 上将 python 3.8 降级到 3.7 后,如何在 PyCharm 中配置解释器? - How to configure interpreter in PyCharm after downgrading python 3.8 to 3.7 on windows? 如何在 windows 10 上安装和使用 python 3.8 和 3.7 - How to install and use both python 3.8 and 3.7 on windows 10 如何在 windows 上将 Python 版本从 3.8 降级到 3.7? - How to downgrade the Python Version from 3.8 to 3.7 on windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM