我第一次在VS代码中安装python的依赖项。之前安装了Python。我在WSL上使用Ubuntu,我的文件结构在Ubuntu的那个文件夹中。我安装了numpy,matplotlib和PyTorch的一个指导项目,我想做的。安装所有软件包后,一切似乎都很好,但从项目中的文件,以验证依赖关系是正确的设置结果在一个错误,模块(import numpy as np)找不到。在搜索numpy文档时,我发现我可能需要在.bashrc文件中添加一行,我确实添加了以下内容:export PYTHONPATH=/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages.在进行此更改后,我得到了一个更详细的错误,我无法找到有用的文档。(下面我发布了一个已安装软件包的列表)
type hestevenseb@DESKTOP-PJJSAIC:~/stock-prediction-model$ /usr/bin/python3.10 /home/stevenseb/stock-prediction-model/project.py
Traceback (most recent call last):
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
from numpy.__config__ import show as show_config
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/usr/bin/python3.10"
* The NumPy version is: "1.26.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/stevenseb/stock-prediction-model/project.py", line 1, in <module>
import numpy as np
File "/home/stevenseb/.pyenv/versions/3.9.4/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.re
字符串
pip install给了我这个:
Package Version
------------------------ ----------
aiohttp 3.9.1
aiosignal 1.3.1
alpha-vantage 2.3.1
async-timeout 4.0.3
attrs 23.1.0
certifi 2023.7.22
charset-normalizer 3.3.2
contourpy 1.2.0
cycler 0.12.1
distlib 0.3.7
filelock 3.12.4
fonttools 4.47.0
frozenlist 1.4.1
fsspec 2023.12.2
idna 3.6
importlib-resources 6.1.1
Jinja2 3.1.2
kiwisolver 1.4.5
MarkupSafe 2.1.3
matplotlib 3.8.2
mpmath 1.3.0
multidict 6.0.4
networkx 3.2.1
numpy 1.26.2
nvidia-cublas-cu12 12.1.3.1
nvidia-cuda-cupti-cu12 12.1.105
nvidia-cuda-nvrtc-cu12 12.1.105
nvidia-cuda-runtime-cu12 12.1.105
nvidia-cudnn-cu12 8.9.2.26
nvidia-cufft-cu12 11.0.2.54
nvidia-curand-cu12 10.3.2.106
nvidia-cusolver-cu12 11.4.5.107
nvidia-cusparse-cu12 12.1.0.106
nvidia-nccl-cu12 2.18.1
nvidia-nvjitlink-cu12 12.3.101
nvidia-nvtx-cu12 12.1.105
packaging 23.2
Pillow 10.1.0
pip 23.3.2
pipenv 2023.9.8
platformdirs 3.10.0
pyparsing 3.1.1
python-dateutil 2.8.2
requests 2.31.0
setuptools 68.2.2
six 1.16.0
sympy 1.12
torch 2.1.2
triton 2.1.0
typing_extensions 4.9.0
urllib3 2.1.0
virtualenv 20.24.5
yarl 1.9.4
zipp 3.17.0
型
这是我尝试运行以验证依赖关系的安装文件:
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import Dataset
from torch.utils.data import DataLoader
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
from alpha_vantage.timeseries import TimeSeries
print("All libraries loaded")
型
我已经使用pip成功安装了python包,但是环境似乎无法访问这些包。我更新了.bashrc中的PATH,但仍然遇到问题。
1条答案
按热度按时间vi4fp9gy1#
我自己找到了答案,我会在这里发布,以防将来有人遇到这个问题。似乎我是在全局安装依赖项,而不是创建一个环境来安装。这在这个链接中解释:https://code.visualstudio.com/docs/python/python-tutorial一旦我按照步骤使用.venv创建一个环境,我就能够安装依赖项,并且它们通过了验证。