My OS is Windows 7
I need to use TensorFlow with Keras in Python , but it doesn't work yet in Python 3.8 . So I've installed again Python 3.7 and his packages.
Inside the IDE PyCharm was easy. 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. 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.
First, I've created the kernels, as iPython instructions said in its site.
python -m ipykernel install --user
It creates a json
file in c:\\Users\\myname\\AppData\\Roaming\\jupyter\\kernels
After I use iPython -h
and he told me to use kernel subcommand:
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
. But I've got a very confusing text.
So I've tried to use the kernel
option,
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 .
I've found a solution that solves my problem in Windows 7. I don't even need ipyKernet
package.
I've started locating iPython.exe
files in Python 3.7 and Python 3.8
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
):
@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
py 37
If I what to run iPython over Python 3.8
py
or
py 38
Of course I've checked Python version in each iPython session:
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.
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
)
Other solution would be temporarily change the path environment variable inside PY.BAT
and any other, if necessary. I haven't done it yet because everything is fine so far.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.