Python进口软件包不存在于环境中

发布于 2025-01-31 15:11:09 字数 1179 浏览 3 评论 0原文

卸载并删除了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文