[英]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中将TensorFlow与Keras一起使用,但它在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.7和Python 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 Panel
、 Systems
、 Advanced system settings
、 environment 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.exe
到pi.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.