Packages installed in my virtual environment arent found unless I install them using cmd prompt in windows

Viewed 37

I am currently working on a python project using Visual Studio Code and Conda. When I try to install a package in the virtual environment it does not work (details and steps below). But if I use my computers command prompt and install that way, it does work in the virtual environment.

My steps are as follows:

I created a virtual environment as so:

conda create -n envname

Activated the environment:

conda activate envname

Tried to install a package (i tried to use conda install but package wasnt found):

pip install packagename 

Then write it into my code like so:

import packagename

Which throws me this error:

ModuleNotFoundError: No module named 'packagename'

I did try the solution from this page and tried installing the package this way:

C:\Users\myname\anaconda3\envs\envname\Scripts\pip install packagename

but it returns this:

Requirement already satisfied: packagename in c:\users\name\anaconda3\envs\envname\lib\site-packages

when i type:

conda list

The package I installed is included, as well as pip. However, the package I installed shows the version # in one column, then only "pypi_0 pypi" in the last column. not sure if that means something is wrong or not.

packagename                  3.41                 pypi_0    pypi

As mentioned, if I type this in my computers command prompt (separate from VSC and my virtual environment):

pip install packagename

My virtual environment will pick it up as being installed.

I feel all mixed up lol, like some path somewhere isnt right but I cant figure out what

Any ideas?

1 Answers

No Need to explicitly activate the venv

Try using following commands.

Step 1: Create virtual env
python -m venv envname

Step 2: Switch to this newly created virtual env
Windows
.\envname\Scripts\activate
Unix
source envname/bin/activate

Step 3: install packages in the virtual env directory
pip install <packagename>

Related