-2

I have a requirement to run my code in python virtual environment, for that I am trying to active the virtual environment through the python script only.

But getting error as: /bin/sh: 1: source: not found

cmd = "source ./nnvm_ndk_tools_env/bin/activate"
process = subprocess.Popen(cmd, stdout=PIPE, shell=True)
Above commands I have added in below script and run the script
python test.py

Output:
source ./nnvm_ndk_tools_env/bin/activate
/bin/sh: 1: source: not found

Can anyone please reply? I have to active the virtual env through python script only.

  • 3
    Possible duplicate of ["source" command in shell script not working](https://stackoverflow.com/q/48785324/608639), [Difference between sh and bash](https://stackoverflow.com/q/5725296/608639), etc. More generally, [command source does not work site:stackoverflow.com](https://duckduckgo.com/?q=command+source+does+not+work+site:stackoverflow.com) – jww Nov 13 '19 at 06:27
  • https://stackoverflow.com/search?q=%5Bvirtualenv%5D+activate+from+Python+script – phd Nov 13 '19 at 14:41

1 Answers1

0

Hi Firstly you have to install virtualenv then create a virtual environment activate that Virtual Environment and then install all python packages you want in that virtual env. Like below

pip install virtualenv
virtualenv myenv

then a virtual env is created in your directory go to that directory

cd myenv
cd Scripts

then simply run a file 'activate'

activate

you can install your packages here Let me know if you still find problem