0

Based on an answer, I've made a Bash script to install the requirements and run a Python script working with a MariaDB database. In WSL, the Python script runs well, but when I run the Bash script from Windows 11 command line, I get following error:

ModuleNotFoundError: No module named 'mariadb'

Unlike another question concerning the same error, I've verified by python3 -V I use Python 3.10 in the whole process. Commenting the MariaDB connector out has shown the same problem with other other imported modules. My Bash, editted:

python3 -m venv "c:\path\to\venv"
"c:\path\to\venv\Scripts\activate"
pip3 install -r "c:/some/path/requirements.txt"
python3 "c:/some/other/path/myscript.py"

The requirements.txt file:

mariadb==1.1.10
datasets
sentence_transformers

EDIT: Thanks to the comments and answers, I've got rid of the following error:

bash: venv/bin/activate: No such file or directory

However, the main problem lasts, it just changed from ImportError to ModuleNotFoundError. All the requirements either install correctly, or report "Requirement already satisfied".

3
  • bash: venv/bin/activate: No such file or directory. error says that you dont have that file. try to check it manually if not there, may try to create the virtual environment manually. Commented Oct 1, 2024 at 8:02
  • So did python3 -m venv venv fail? You can use set -e to force Bash to exit when a command fails, or python -m venv venv || exit to explicitly exit if this fails. Commented Oct 1, 2024 at 8:02
  • @HenroSutrisnoTanjung I've used the same command as in the WSL. Probably, I must install Docker outside WSL too to make it work. Thanks for a hint! Commented Oct 1, 2024 at 8:06

4 Answers 4

1

If you are on Windows (command line or bash), the installation layout is different from *nix.

activate is a batch file and stored under venv/scripts.

See also: How venvs work

Sign up to request clarification or add additional context in comments.

Comments

0

I think problem is how you are trying to activate the environment, It should activate like this

venv\Scripts\activate

Then you can try to install requirement.txt

pip install -r requirement.txt #add path if have

1 Comment

No, that's not correct for Bash; you need to source the activate script, and backslashes are not acceptable as directory separators.
0

Solved! Ruwan's note #add path if have pushed me to analyze the requirement.txt call deeper. That's how I've found the solution. I changed the line to:

python3 -m pip install -r "c:/some/path/requirements.txt"

The pip3 was linked to another version of Python (3.8 in my case). python3 -m tied it to the right one.

1 Comment

well, Happy to help you somehow. :)
0

You need

source "c:\path\to\venv\Scripts\activate"

to activate the virtual environment from bash.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.