我有一个脚本gapminder1.py,它使用panda和sklern。
# TODO: Add import statements
import pandas as pd
from sklearn.linear_model import LinearRegression
# Assign the dataframe to this variable.
# TODO: Load the data
bmi_life_data = pd.read_csv("CSV_DATA/bmi_and_life_expectancy.csv")
print(bmi_life_data)
# Make and fit the linear regression model
#TODO: Fit the model and Assign it to bmi_life_model
bmi_life_model = LinearRegression()
bmi_life_model.fit(bmi_life_data[['BMI']], bmi_life_data[['Life expectancy']])
# Make a prediction using the model
# TODO: Predict life expectancy for a BMI value of 21.07931
laos_life_exp = bmi_life_model.predict(21.07931)
我正在运行来自cmd控制台的脚本,运行良好,但是来自pycharm的相同脚本显示了错误
C:\Users\tripathi\AppData\Local\Continuum\anaconda3\envs\dsnd\python.exe C:/Users/tripathi/PycharmProjects/dsnd/gapminder1.py
Traceback (most recent call last):
File "C:/Users/tripathi/PycharmProjects/dsnd/gapminder1.py", line 3, in <module>
import pandas as pd
File "C:\Users\tripathi\AppData\Local\Continuum\anaconda3\envs\dsnd\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
我在这两个地方使用相同的conda环境,但不确定为什么它不能正常工作。
这是PyCharm在Windows上的一个已知问题。使用conda环境,但PyCharm实际上没有激活它,因此环境变量不会被加载。这个问题已经有一段时间了,似乎很容易解决,但是由于某种原因他们还没有解决。
唯一的解决方法是从激活env的cmd窗口启动PyCharm,或者在作为外部工具执行之前运行环境激活。
您必须使用pycharm设置将numpy安装到conda虚拟环境中。
三。从“可用软件包”列表中搜索并选择“numpy”,然后单击“安装软件包”。
好吧,我认为这是康达和皮查姆之间沟通不正常的问题。这就是为什么我总是使用PyCharm创建我的虚拟环境。
选项1:使用PyCharm创建新的虚拟环境
试试instructions by jetbrains。
选项2:删除并重新连接到旧的Conda环境并检查设置
也许你在通过PyCharm连接到环境时没有选中一些框:
相关问题 更多 >
编程相关推荐