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!
问题:
回答1:
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.....
回答2:
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
.
回答3:
this happened to me when installing numpy but after i restarted VScode it fixed it's self. if that didn't work check that the package is installed with: pip list in the command prompt.