Python进口软件包不存在于环境中
卸载并删除了TensorFlow后,该软件包不再存在于当前环境的Conda/Pip软件包列表中。当前目录中都没有任何关联的文件。那么,如何在没有A ModulenotFoundError 的情况下导入TensorFlow软件包?奇怪的是,可以导入模块,但不可能打印其版本。在Python中对此有什么解释?
找不到包装:
(base) $ which python
/Users/foobar/miniforge3/bin/python
(base) $ pip show tensorflow
WARNING: Package(s) not found: tensorflow
(base) $ conda env list
# conda environments:
#
base * /Users/foobar/miniforge3
(base) $ conda list tensorflow --full-name
# packages in environment at /Users/foobar/miniforge3:
#
# Name Version Build Channel
不在模块列表中的软件包:
(base) $ python3
Python 3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:27:43)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")
即使不在模块列表中,软件包也可以导入:
>>> import tensorflow as tf
>>> tf.__version__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute '__version__'
After having uninstalled and removed tensorflow, the package is no longer present in the current environment's conda/pip package list. Neither are there any associated files present in the current directory. How then, is it possible to import the tensorflow package without a ModuleNotFoundError ? Strangely, the module can be imported but it is not possible to print its version. What is the explanation for this in python?
Package not found:
(base) $ which python
/Users/foobar/miniforge3/bin/python
(base) $ pip show tensorflow
WARNING: Package(s) not found: tensorflow
(base) $ conda env list
# conda environments:
#
base * /Users/foobar/miniforge3
(base) $ conda list tensorflow --full-name
# packages in environment at /Users/foobar/miniforge3:
#
# Name Version Build Channel
Package not in module list:
(base) $ python3
Python 3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:27:43)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")
Package is able to be imported even though it is not in module list:
>>> import tensorflow as tf
>>> tf.__version__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute '__version__'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论