Home > Software design >  Problem installing Python requirement in WSL with venv
Problem installing Python requirement in WSL with venv

Time:05-25

I have a code repository from a vendor and I'm trying to set up my local system in the exact same way that they did (as much as possible)

I'm running Ubuntu in WSL for Windows already so I figured I would try to also use this system for this vendor repo. In the repo there is a shell script which looks like this:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

For case of argument, lets call this file "runner.sh"

First thing to note here is that I do not have a user in my Ubuntu/WSL called 'vendorname' as would be suggested by the location of the vendorname folder under home. Not sure if that is an issue but it might be.

Second, I have set up my file structure exactly the same as this shell script seems to indicate. I have placed my code repository under /home/vendorname and I have used venv to create a virtual environment located under /home/vendorname/.virtualenvs/vendor-app.

I have also activated my virtual environment with the following command:

source /home/vendorname/.virtualenvs/vendor-app/bin/activate

My problem

When I run the runner.sh file from the command line I get the following error:

Traceback (most recent call last):
  File "/home/vendorname/vendor-app/vendor_script.py", line 17, in <module>
    import requests
ModuleNotFoundError: No Module named 'requests'

This error seems to indicate that the requests module is not installed however whenever I try to install it I get the "Requirement already satisfied" response.

Any ideas?

CodePudding user response:

The problem was in line 3 of the shell script:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

Which should have looked like this:

#!/bin/bash
cd /home/vendorname/vendor-app
. source /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

Not sure how this ever worked but that fixed my problem locally

  • Related