当前位置:网站首页>Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed

Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed

2022-07-06 00:21:00 It's Yu

Change the computer again , Download the configuration again

One 、aconda download

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

conda channel Mirror settings for ( Reference resources https://blog.csdn.net/weixin_39278265/article/details/84782550)
Show all channel

conda config --show channels

Two 、 Add available Tsinghua sources

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

conda config --set show_channel_urls yes I mean from channel Displays when installing packages in channel Of url, In this way, you can know the installation source of the package .

(3) Input conda config --show channels Check whether the addition is successful .
According to the image source you added , Which did you add , Just show which .
 Insert picture description here

3、 ... and 、tensorflow Installation

(1)win+r Input cmd, Check anaconda install : stay cmd Input conda --version

(2) Detect the installed environment :conda info --envs
If there is no new environment here , There is only one default anaconda Medium root Environmental Science .

(3) Create a new one python3.5 Environment ,tensorflow:conda create --name tensorflow python=3.6
The system will automatically choose to assign one python3.6.x Version of

(4) Check if the creation is successful :conda info --envs
 Insert picture description here

(5) Activate the new environment :activate tensorflow
Be sure to enter tensorflow in , Otherwise, you will install it in other environments , Make it unusable .

(6) Inquire about tensorflow Version number of
conda search tensorflow

(7) Choose the version number you want to install .conda install tensorflaw= Version number
( Such as :conda install tensorflaw=2.0.0) And then go back , Wait for .

If the following error occurs after installation
Fatal Python error: Py_Initialize: can’t initialize sys standard streams LookupError: unknown encoding: 65001
You can enter it in the command window set PYTHONIOENCODING=UTF-8

4. testing tensorflow Is the installation successful
(1) open cmd, Activate the new environment ( Switch to tensorflow Environmental Science ):activate tensorflow

(2) Get into python

(3) Then type in a tensorflow edition 1.5 Test code : If the output results 3, Description has been successfully installed tensorflow.

import tensorflow as tf 
sess = tf.Session() 
a = tf.constant(1) 
b = tf.constant(2) 
print(sess.run(a+b)) 

tensorflow edition 2.0 Test code :

import tensorflow as tf

# see tensorflow edition 
print(tf.__version__)

print('GPU', tf.test.is_gpu_available())

a = tf.constant(2.0)
b = tf.constant(4.0)
print(a + b)

 Insert picture description here

Four 、 Problems and solutions

1、 Report errors :No module named ‘tensorflow’

Reference resources :https://blog.csdn.net/qq_40305998/article/details/105677341
windows Terminal can import tensorflow,jupyter Impossible solution
 Insert picture description here
 Insert picture description here
If not , There is a problem .

Input in the terminal :

jupyter kernelspec list

Show what has been added kernel

Then input :

conda install pip
conda install ipykernel

python -m ipykernel install --user --name tensorflow --display-name tensor

among :
python -m ipykernel install --user --name “ Name of the environment ” --display-name “ Want to name Python name ”
 Insert picture description here
Input again :

jupyter kernelspec list

You can see one more kernel.

open jupyter notebook, You can see an additional one named tensor Of kernel.
 Insert picture description here

newly build tensor Of notebook file , You can solve the problem

You can also use :

jupyter kernelspec remove tensorflow

Delete the created kernel.

among

jupyter kernelspec remove <kernel_name>

Input again :

jupyter kernelspec list

open jupyter, Created Python have been deleted .

2、Kernel does not exist

Reference resources https://blog.csdn.net/Julse/article/details/102555574

stay pycharm Of terminal In the end , For the first time to start jupyter notebook, success . Restart after interruption , function cell I couldn't find it kernels, The system reports an error as follows

(topvenv)..../feature190919>jupyter notebook
[I 11:11:59.261 NotebookApp] Serving notebooks from local directory: ..../feature190919
[I 11:11:59.261 NotebookApp] The Jupyter Notebook is running at:
[I 11:11:59.261 NotebookApp] http://localhost:8888/?token=...
[I 11:11:59.262 NotebookApp] or http://127.0.0.1:8888/?token=...
[I 11:11:59.262 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 11:15:08.362 NotebookApp] No session ID specified
[W 11:15:08.362 NotebookApp] 404 GET /api/kernels/96b59d42-d81e-471c-8ef9-63a61a963a16/channels (127.0.0.1): Kernel does not exist: 96b59d42-d81e-471c-8ef9-63a61a963a16
[W 11:15:08.369 NotebookApp] 404 GET /api/kernels/96b59d42-d81e-471c-8ef9-63a61a963a16/channels (127.0.0.1) 9.02ms referer=None
[I 11:21:39.267 NotebookApp] Interrupted...
[I 11:21:39.268 NotebookApp] Shutting down 0 kernels

Solution ( Failure ):
To find the runtime Catalog , Empty it all , restart jupyter That's all right. ( Be careful APPData For hidden folders )
 Insert picture description here
 Insert picture description here

The following is my analysis and solution to this error
I'll go straight to token This error is caused by the password filled in the parameter of

Observe the directory , One start jupyter notebook These three files are generated
 Insert picture description here

Open in Notepad nbserver-2280.json file , Will find 123456 I didn't get into password Field , Instead, it was put into token Field . At this time in pycharm Click on the

At this time, you will be prompted to enter the password again
 Insert picture description here

Enter the password and save it .

stay cmd Through the window pip install jupyter After successful installation , function jupyter notebook, Run code , Find the left side of the code In [ ] Turned into In [*], Found in cmd The error reported in the window is as follows :

3、KernelRestarter: restart failed, Kernel restart failed

There is also a large section of error reporting on this , It probably means that you are constantly trying to restart the kernel , Reading newspapers is wrong , Mainly KernelRestarter: restart failed, Kernel restart failed

Solution ( success ):

pip install --upgrade ipykernel

Upgrade it to run normally , Although it will remind you prompt-toolkit The version of should be in 1.0 To 2.0 Between , But it doesn't affect jupyter notebook Operation of , In the process of upgrading , The main updated module is prompt_toolkit, It seems that the version of this module is too low

Reference resources :https://blog.csdn.net/weixin_40820983/article/details/102798873
Because you need to upgrade the version of some packages , use pip install --upgrade *** The command to update , However, it is impossible to uninstall :

ERROR: Cannot uninstall ‘scikit-learn’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Some answered with

pip install --ignore-installed ipykernel 

But the old version is still , There will be other problems .

In fact, as long as you find it python Installation package in , Delete all files related to it .( All files with this module in their names should be deleted )

For example, in the folder :anaconda\Lib\site-package
 Insert picture description here
D:\Program\Anaconda\envs\tensorflow\Lib\site-packages
 Insert picture description here
Reference resources :https://blog.csdn.net/qq_45371443/article/details/119008541

conda install tensorflow-estimator==2.0.0

 Insert picture description here
Then reinstall , success !!!

pip install --ignore-installed ipykernel 

 Insert picture description here
 Insert picture description here
It worked

原网站

版权声明
本文为[It's Yu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060017356279.html