尽管反复安装了图书馆,但我无法将库导入Python

发布于 2025-02-01 20:58:14 字数 3145 浏览 2 评论 0 原文

我正在努力将Python库安装和导入到我的程序中。最初我正在使用PYDEV,但我一直收到诸如:

trackback(最近的呼叫最后)的消息:文件“ c:\ users \ users \ eclipse-workspace \ dmd dmd实验\ main.py”,第11行,in<模块>从matplotlib导入pyplot作为绘图ModulenotFoundError:无模块,名为“ matplotlib'

i使用 py> py -m pip install matplotlib i安装matplotlib ,它产生了一些类似这样的消息。

警告:脚本f2py.exe已安装在'c:\ users \ super \ appdata \ local \ program \ python \ python \ python310 \ scripts'中,这不在路径上。考虑将此目录添加到路径上,或者,如果您希望抑制此警告,请使用 - 不使用-Warn-script-Location。警告:脚本fonttools.exe,pyftmerge.exe,pyftSubset.exe和ttx.exe已安装在'c:\ users \ users \ users \ sufter \ appdata \ local \ program \ python \ python \ python \ python310 \ scriptss中。代码>

我不确定这是什么意思,所以我尝试再次运行程序,并再次找到模块的错误。

由于无法解决我搬到Spyder的问题,因为它带有我想要的许多库,从而避免了问题。但是,一旦我尝试导入和安装Spyder未包含的库,我就遇到了该模块未发现错误和有关路径的类似警告。我现在在Spyder中添加了警告中提到的路径时,当我运行代码时,我会收到此错误消息:

runfile('C:/Users/satur/.spyder-py3/proper orthogonal decomposition/dynamic mode decomposition experimental driver.py', wdir='C:/Users/satur/.spyder-py3/proper orthogonal decomposition')
Traceback (most recent call last):

  File "C:\Users\satur\AppData\Local\Programs\Spyder\pkgs\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\satur\.spyder-py3\proper orthogonal decomposition\dynamic mode decomposition experimental driver.py", line 13, in <module>
    import mat73

  File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\mat73\__init__.py", line 11, in <module>
    import h5py

  File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py", line 25, in <module>
    from . import _errors

ImportError: cannot import name '_errors' from partially initialized module 'h5py' (most likely due to a circular import) (C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py)

我进行了一些环境,发现了此

我遵循了我理解的指示

import sys; sys.executable

out [ 50]:'c:\\ user \\ appdata \\ local \\ program \\ spyder \\ python \\ python \\ python.exe'

它与我在命令中运行的内容有所不同提示或在PYDEV终端中,这两个都给我

c:\ users \ super \ appdata \ local \ Microsoft \ Microsoft \ Windows \ WindowsApps \ pythonsoftwarefoundation.python.3.9_qbz5n2kfra8ppra8pp0

c:\ users \ appdata \ local \ local \ microsoft \ windowsapps \ pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0 \ i i看到:IDEL的3个版本,IDEL,3个版本的PIP和6个版本和6个版本。

我很困惑。我想安装和导入库中的Python程序。我希望能够在IDE中(或为此)运行我的程序。我似乎都遇到了非常相似的问题。我在网上找到的每个教程都描述了要执行此操作的步骤,但不是它们是什么,或者为什么我这样做似乎都没有工作,而我尝试安装内容的次数越多,我就会变得更加困惑。

有人可以解释一下:如何将库安装和导入到Python程序中。 Python安装物品并尝试导入它们时正在做什么。以及为什么两个IDE都有相似但不同的错误。

I am struggling to install and import python libraries into my programs. originally I was using pydev but I kept getting messages like:

Traceback (most recent call last): File "C:\Users\satur\eclipse-workspace\DMD experimental\Main.py", line 11, in <module> from matplotlib import pyplot as plot ModuleNotFoundError: No module named 'matplotlib'

I installed matplotlib using py -m pip install matplotlib which produced a few messages like this.

WARNING: The script f2py.exe is installed in 'C:\Users\satur\AppData\Local\Programs\Python\Python310\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts fonttools.exe, pyftmerge.exe, pyftsubset.exe and ttx.exe are installed in 'C:\Users\satur\AppData \Local\Programs\Python\Python310\Scripts' which is not on PATH.

I was unsure what this meant so I tried running my program again and got the module not found error again.

being unable to resolve the issue I moved over to spyder because it came with many of the libraries I wanted thus avoiding the issue. however, as soon as I tried to import and install libraries not included with spyder I encountered the module not found error and a similar warning about the path. I added the paths mentioned in the warning to the PATH in spyder now when I run my code get this error message:

runfile('C:/Users/satur/.spyder-py3/proper orthogonal decomposition/dynamic mode decomposition experimental driver.py', wdir='C:/Users/satur/.spyder-py3/proper orthogonal decomposition')
Traceback (most recent call last):

  File "C:\Users\satur\AppData\Local\Programs\Spyder\pkgs\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\satur\.spyder-py3\proper orthogonal decomposition\dynamic mode decomposition experimental driver.py", line 13, in <module>
    import mat73

  File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\mat73\__init__.py", line 11, in <module>
    import h5py

  File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py", line 25, in <module>
    from . import _errors

ImportError: cannot import name '_errors' from partially initialized module 'h5py' (most likely due to a circular import) (C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py)

I did some looking around and found this

https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#installing-packages-into-the-same-environment-as-spyder

I followed what instructions I understood

import sys; sys.executable

Out[50]: 'C:\\Users\\satur\\AppData\\Local\\Programs\\Spyder\\Python\\python.exe'

which is different from what I get when I run it in command prompt or in the pydev terminal both of which give me

C:\Users\satur\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe

when i go to C:\Users\satur\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\ I see: 3 versions of idel, 3 versions of pip, and 6 versions of python.

I am deeply confused. I want to install and import libraries into my python programs. I want to be able to run my programs in either (or for that matter any) ide. I seem to be hitting the very similar issues in both. every tutorial I have found online describes the steps to take to do this but not what they are or why I am doing them none of them seem to work and the more times I try to install things the more confused I get.

could someone please explain: how to install and import libraries into a python program. what python is doing when I install things and try to import them. and why both IDEs have similar but different errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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