Reputation: 61
My lap is MacBookPro2017, macOS Mojave 10.14.16
I used to coding in Jupyter and everything goes well.
However when I want to do the same thing in VScode, it said that
"ImportError: No module named pandas"
I am sure I have installed pandas by
pip3 install pandas
I do following things:
1.Search for similar problems on SO, and someone says there may be more than one version python, the pip and pandas may under another path. Then I find there are python2.7 and python3.7 in my lap:
AlfiedeMacBook-Pro:~ alfie$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
AlfiedeMacBook-Pro:~ alfie$ which python
/usr/bin/python
AlfiedeMacBook-Pro:~ alfie$ which pip
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip
AlfiedeMacBook-Pro:~ alfie$ which pip3
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
AlfiedeMacBook-Pro:~ alfie$ which pandas
AlfiedeMacBook-Pro:~ alfie$ pandas --version
-bash: pandas: command not found
AlfiedeMacBook-Pro:~ alfie$ pip --version
pip 19.2.2 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
And if I type:
AlfiedeMacBook-Pro:~ alfie$ pip3 install pandas
Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.25.1)
Requirement already satisfied: pytz>=2017.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2019.2)
Requirement already satisfied: python-dateutil>=2.6.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.8.0)
Requirement already satisfied: numpy>=1.13.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.17.0)
Requirement already satisfied: six>=1.5 in ./Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.6.1->pandas) (1.12.0)
So I think I have pandas in the true path(?)
2.Then I saw some one use sys to append the path, so I write it in front of my code:
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages')
import numpy as np
import pandas as pd
Then I got:
ImportError: this version of pandas is incompatible with numpy < 1.13.3
your numpy version is 1.8.0rc1.
Please upgrade numpy to >= 1.13.3 to use this pandas version
But my numpy version is 1.17, I have upgraded.
So I just want know what I should do to make the pandas can be used in VScode?
Upvotes: 6
Views: 12937
Reputation: 110
For beginner: The answer kinda was given above, but I took a long time to find the exact solution.
python --version
if it doesn't work type `python3 --version``python3 -m venv venv
this will create a virtual environment what is the recommended way to deal with your projects. A important reminder, it'll create the environment in the current folder that you're with your project. venv/bin/activate
will activate your project. For some systems you don't even need to do it, but for me was necessarypython3
import sys
print(sys.executable)
pip install module
I hope it'll work for you peeps! I finally got my program working from here.
Upvotes: 3
Reputation: 369
Having that problem while being in a properly set up environment, the first you should do is to close all vscode windows and then start it fresh.
I've stumbled on that today and it has worked.
Upvotes: 0
Reputation: 1401
I also faced the same issue. My Python version in VS Code was same as Terminal. Same environment. Same sys.executable
path. But the PATH
in os.environ
found in command prompt/spyder Console/Jupyter terminal
was different compared to the PATH
I got from VS Code terminal.
VS Code starts PATH
like this from os.environ['PATH']
:
'PATH': 'C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;...'`
And terminal starts PATH
like this from os.environ['PATH']
:
'PATH': 'C:\\Users\\userid\\Appdata\\Local\\Continuum\\Anaconda3;...'
So when I replaced the PATH
variable to start with my anaconda path, Import pandas worked fine.
Though Anaconda Path was present in VS Code PATH
variables also, it was at the end. So I guess it was changed by VS Code in startup.
Upvotes: 1
Reputation: 136379
I had the same issue. The problem was that VS Code was using a different environment (shown in the lower left corner). Switching the environment there solved the issue.
Upvotes: 11