无法使用jupyter笔记本导入Python中已安装的包

问题描述 投票:0回答:1

我有一个奇怪的问题。我想在 Python 中使用“copulas”包(https://sdv.dev/Copulas/)。为此,我首先使用安装它

!pip install copulas

输出是

Requirement already satisfied: copulas in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (0.10.0)
Requirement already satisfied: plotly<6,>=5.10.0 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from copulas) (5.19.0)
Requirement already satisfied: numpy<2,>=1.23.3 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from copulas) (1.26.4)
Requirement already satisfied: scipy<2,>=1.9.2 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from copulas) (1.12.0)
Requirement already satisfied: pandas>=1.5.0 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from copulas) (2.2.0)
Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from pandas>=1.5.0->copulas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from pandas>=1.5.0->copulas) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from pandas>=1.5.0->copulas) (2024.1)
Requirement already satisfied: tenacity>=6.2.0 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from plotly<6,>=5.10.0->copulas) (8.2.3)
Requirement already satisfied: packaging in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from plotly<6,>=5.10.0->copulas) (23.2)
Requirement already satisfied: six>=1.5 in c:\users\wi9632\appdata\local\programs\python\python311\lib\site-packages (from python-dateutil>=2.8.2->pandas>=1.5.0->copulas) (1.16.0)


[notice] A new release of pip available: 22.3.1 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip

然后我使用以下代码检查它是否已安装:

!python --version
!pip list

这导致输出:

Python 3.11.3
Package         Version
--------------- -------
copula          0.0.4
copulas         0.10.0
numpy           1.26.4
packaging       23.2
pandas          2.2.0
pip             22.3.1
plotly          5.19.0
python-dateutil 2.8.2
pytz            2024.1
scipy           1.12.0
setuptools      65.5.0
six             1.16.0
tenacity        8.2.3
tzdata          2024.1


[notice] A new release of pip available: 22.3.1 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip

当我尝试使用代码导入模块时:

# import all relevant libraries
import scipy.stats as stats
import numpy as np
import pandas as pd
import datetime as dt
import re
from matplotlib import pyplot as plt
import pickle
import copulas

我收到错误:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-8-cec22cbc11bb> in <module>
      7 from matplotlib import pyplot as plt
      8 import pickle
----> 9 import copulas

ModuleNotFoundError: No module named 'copulas'

以下是一些附加信息:

import sys
print(sys.path)

导致输出:

['C:\\Users\\wi9632\\bwSyncShare3\\Eigene Arbeit\\Code\\Python\\lademodellierung-main', 'c:\\users\\wi9632\\python\\python39\\python39.zip', 'c:\\users\\wi9632\\python\\python39\\DLLs', 'c:\\users\\wi9632\\python\\python39\\lib', 'c:\\users\\wi9632\\python\\python39', '', 'c:\\users\\wi9632\\python\\python39\\lib\\site-packages', 'c:\\users\\wi9632\\python\\python39\\lib\\site-packages\\win32', 'c:\\users\\wi9632\\python\\python39\\lib\\site-packages\\win32\\lib', 'c:\\users\\wi9632\\python\\python39\\lib\\site-packages\\Pythonwin', 'c:\\users\\wi9632\\python\\python39\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\wi9632\\.ipython']

import sys
sys.executable

导致输出:

'c:\\users\\wi9632\\python\\python39\\python.exe'

你能告诉我,为什么我可以安装库但不能导入它吗?

python jupyter-notebook python-packaging copula
1个回答
0
投票

主要问题是您安装的 Python 版本与您正在使用的不同。包含该软件包的版本是 3.11.3,您要激活的版本是 3.9。 如果您想使用 3.9 版本,可以使用

pip3.9 install copulas
安装 3.9

© www.soinside.com 2019 - 2024. All rights reserved.