问题
I installed latest version of tensorflow that is 2.3 and when i try to import tensorflow i get below error
runfile('C:/Users/Sriram/untitled1.py', wdir='C:/Users/Sriram')
Traceback (most recent call last):
File "<ipython-input-7-ae532bb97ae9>", line 1, in <module>
runfile('C:/Users/Sriram/untitled1.py', wdir='C:/Users/Sriram')
File "C:\Users\Sriram\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 435, in runfile
__umr__.run()
File "C:\Users\Sriram\anaconda3\lib\site-packages\spyder_kernels\customize\umr.py", line 133, in run
if self.is_module_reloadable(module, modname):
File "C:\Users\Sriram\anaconda3\lib\site-packages\spyder_kernels\customize\umr.py", line 77, in is_module_reloadable
if (path_is_library(getattr(module, '__file__', None),
File "C:\Users\Sriram\anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
from ._api.v2 import audio
File "C:\Users\Sriram\anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
# Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.
File "C:\Users\Sriram\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow_core'
Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x000001276F806208>> (for post_execute):
Traceback (most recent call last):
File "C:\Users\Sriram\anaconda3\lib\site-packages\IPython\extensions\autoreload.py", line 538, in post_execute_hook
_, pymtime = self._reloader.filename_and_mtime(sys.modules[modname])
File "C:\Users\Sriram\anaconda3\lib\site-packages\IPython\extensions\autoreload.py", line 184, in filename_and_mtime
if not hasattr(module, '__file__') or module.__file__ is None:
File "C:\Users\Sriram\anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
from ._api.v2 import audio
File "C:\Users\Sriram\anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
# Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.
File "C:\Users\Sriram\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow_core'
I downloaded some msvdp71 zip file and extracted it and copied it in my sys32 and syswow folders it didnt work for me.In colab i trained few models and i want to run them on pc when i try to run them with tf1.6.0 they gave errors related to version .so when i upgraded it using pip i was not even able to import it.
回答1:
Create a virtual environment in python. For the creation of a virtual environment, you need virtualenv library.
pip install virtualenv
After installing create your virtual environment.
command - virtualenv "NAME-OF-ENVIRONMENT"
eg
virtualenv myenv
This will create a directory called myenv. To activate the virtual environment you have go inside the myenv/scripts folder, open a cmd prompt and type activate.
eg
cd myenv/Scripts
activate
Get out of the Scripts folder
cd ../..
Now install TensorFlow.
pip install tensorflow
Tensorflow requires various libraries to work. As you know TensorFlow 1.x and 2.x are not compatible. When you ran the upgrade script it must have only upgraded the version and not downloaded the dependency.
Note: Always create a virtual environment when working in any project and keep your python package clean. You can delete these environments if they become corrupt or stop working correctly due to any reason, without and fear.
来源:https://stackoverflow.com/questions/63649509/problem-with-setting-up-tensorflow-on-windows