Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Import in VS Code

I'm new to python and I've been using VS code. Right now I'm working on a Thompson Sampling problem that requires numpy and matplotlib. I've imported both libraries but VS code is giving the error unable to import. I know I have to install with PIP, and I have seen other solutions about changing the Python path through the json. but I'm afraid to do that because I don't want to mess up my text editor. Can someone walk me through what I am supposed to do? I haven't seen any simple tutorials on setting up VS Code for python. I'm hoping this will help other people too! I have the extensions Python and CodeRunner installed in VS code. Thank you!

like image 710
Ashley E. Avatar asked Jan 19 '19 23:01

Ashley E.


2 Answers

solution to this is make virtual environment for your project steps are as follows
1.go to specifid directory you want to make project.
2.open cmd or teminal an type mkdir testProjectName.
3.type cd testProjectName.
4.type virtualenv venv.
5.type for windows source venv/scripts/activate
type for linux or mac source venv/bin/activate
6.type pip install python.
7.type pip install numpy.
8.type pip install matplotlib.
9.make your project 'testProjectName' dir or copy and paste you project here.
Hope this helps.....

like image 75
dvijparekh Avatar answered Oct 09 '22 14:10

dvijparekh


If you're using Python 3, the issue is most likely that when you installed numpy and matplotlib you used the pip command, which will only install them for Python 2. To install the libraries for Python 3 just use the pip3 command in place of pip.

like image 40
jbinvnt Avatar answered Oct 09 '22 14:10

jbinvnt