i have a script gapminder1.py which uses the panda and 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)
i am running the script from cmd console which is working fine but the same script from pycharm showing me the error
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']
i am using same conda environment on both the places but not sure why it is not working fine.
This is a known issue in PyCharm on Windows at least. The conda environment is used but not actually activated by PyCharm so environment variables for the env are not loaded. It's been a problem for a while, seems it'd be easy to fix but for some reason they haven't fixed it.
The only work around is to start PyCharm from a cmd window in which the env is activated, or possibly run the environment activation prior to execution as an external tool.
Okay, I think it's an issue where Conda and pycharm are not communicating with each other properly. This is the reason why I always create my virtual environment using PyCharm.
Try the instructions by jetbrains.
Perhaps you didn't check some of the boxes when connecting to the environment via PyCharm:
You have to install numpy into the conda virtual environment using pycharm settings.
3. Search and select numpy from the available packages list and click install package.
Make sure you have pip installed numpy, also check on the paths at environment variables at My Computer or Control Panel.
Method 1
Try uninstaling and again installing pandas and numpy by:
conda uninstall pandas
conda uninstall numpy
conda install pandas
conda install numpy
You have to do this using the same python(conda) environment which is in the question
Method 2
Try deleting all .pyc files in the project directory
Method 3
Try importing numpy in your gapminder1.py by adding a import numpy
line at the top
You might need to use multiple methods. Follow the solution according to the given order.
Hope it helps. Thanks and regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With