0

I am trying to run a script I wrote and I hope to distribute. Each time I run outside of an activated virtual environment "No module named", I guess it is because it has some dependencies that are not in-built. How do I overcome this issue ?

3
  • Show your script and the error message of your command pls Commented Sep 28, 2022 at 10:04
  • The script works. The error message it shows on the command line occurs when a virtual environment is not activated, the error "no module ..... found". I can install all the dependencies to my python library and it works but I plan to distribute this script that will be inconvenient for whoever uses it. Commented Sep 28, 2022 at 10:16
  • If, by "distribute", you mean the eventual user will run something like pip install your_cool_script, then the distribution package will ensure that the necessary modules are installed at that time. Commented Sep 28, 2022 at 13:32

2 Answers 2

2

You need to install that modules outside the virtual environment that is directly in the system.

And If you want to distribute your script then add all of your required modules in requirements.txt file and provide this file to another user along your script and then just run this command to install the modules:-

pip install -r requirements.txt

OR

python3 -m pip install -r requirements.txt
Sign up to request clarification or add additional context in comments.

Comments

1

You need to create a requirements file, those who want to use your project can run the command provided by Dinky Arora to get the required packages.

I recommend downloading pipreqs which helps your generate requirement files by running the following command :

pip install pipreqs

Then run :

pipreqs /path/to/project

To generate a requirements file.

Note : You can also use freeze, it does the same job. Moreover, you could generate a setup.py to install your python project + all its dependencies.

1 Comment

I am aware of this method. I was juts wondering if there was a way when they run the script and the script detects missing packages and installs them first before going on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.