简体   繁体   中英

Using my virtual environment - where is python?

I'm an extreme newbie with regards to Python, and I'm following this tutorial to get started. I've been struggling to get my virtual environment to work. I'm able to get to installing the packages (step 3 in the "Install and use packages" section) but when I then try to run the import lines after installing the packages in my virtual environment I still get ModuleNotFoundError: No module named 'matplotlib' and same for numpy.

When I navigate in File Explorer I can find a folder called.venv in my project folder, and within it Lib/site-packages seems to have the modules that I'm looking for. Which makes me think I'm not correctly using the virtual environment. I saw here that some people had this problem when they were in the wrong Python environment, so I tried typing where python but I didn't really get...anything?

python结果在哪里

My guess is I'm missing something very fundamental/obvious but I can't figure out what it is!

Maybe not the real answer of your question, but this may help. It have a good compatibility with Visual Studio Code too.

Here is the step I used everytime I create a virutal environement:

First, as one time install, I need to install pipenv globaly with:

$ pip install pipenv

Next, everytime I need to create a virtual environement for the project I'm in I just use these command:

$ pipenv shell
$ pip install python_package_name

Note that pipenv shell will create a new virtual environement if it doesn't exist or activate the existing one.

To activate it in the project folder, just retype this is enough:

$ pipenv shell

You can read more about pipenv here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM