Dave
Dave

Reputation: 454

Module installed in virtual environment, yet my program raises a ModuleNotFoundError

I'm struggling to understand what just might be happening here:

(bvBot_env) C:\Users\You_A\>python -c "import ujson"

(bvBot_env) C:\Users\You_A\>main.bat
Traceback (most recent call last):

  File "C:\Users\You_A\ line 9, in <module>
    import ujson as json
ModuleNotFoundError: No module named 'ujson'

The main python version on my os is 3.6. The version in my venv is 3.5.2. ujson is not installed version 3.6.

EDIT(contents of .bat file):

@py.exe C:\Users\You_A\Desktop\VirtualEnvironments\bvBot_env\bvBot\bvBot\main.py %*
@pause

EDIT The problem resides with the batch file. This avoids the ModuleNotFoundError:

>python main.py

Upvotes: 1

Views: 148

Answers (1)

9000
9000

Reputation: 40894

You're likely not activating the python interpreter from the virtual environment.

What you have to do is

path\to\virtual\environment\python.exe path\to\script\main.py

The two paths may be the same, but calling the right python.exe is crucial.

Upvotes: 2

Related Questions