Activate the virtual environment to run a python script

61 views Asked by At

I'm trying to run a Python script (written in Pycharm for Windows) in a linux system (laptop without internet connection). I have my folder with my script (main.py) and my venv folder. I tried to activate the virtual environment using source /project/venv/Scripts/activate and then running python3 /project/main.py but here it says ModuleNotFoundError: No module named 'numpy'. I know that the module is in the virtual environment site-packages so I assume that I didn't activate the venv properly. Any help?

2

There are 2 answers

0
Paul Schulze On

have you tried running the script in the terminal with

.venv/bin/python /directory/of/main.py

This would help in determining if there is a problem with the activation or the environment.

0
bbaassssiiee On

Your virtualenv is active after source /project/venv/Scripts/activate. You need to install numpy into it, but the linux laptop has no internet.

A pip install numpy would be used if connected to the internet. You can proxy pip with a ~/.pip/pip.conf file.

[global]
proxy = http://proxy:3128

If no proxy then you could build Numpy from source provide the linux laptop has a working C++ compiler and the development packages for your version of Python, and wheel.

Furthermore there are "build dependencies" distributed as wheels: packaging, meson, Cython, pyproject-metadata, meson-python, patchelf, ninja. These are collected at build-time, therefore an air-gapped build has additional challenges.