Report this

What is the reason for this report?

activating virtualenv and running python script in bash file

Posted on January 25, 2017

I would like to know how to activate a python virtual env and running a python script inside a bash file.

When I go to my environment directory and do “source name_Env/bin/activate” (without quotes ofcourse) it activates like normal and I can run script.py without getting configparser errors. But with doing that in bash it seems like it doesnt know the path to the activate file / the activate file

The file:

#! /bin/bash
source name_Env/bin/activate
# virtualenv is now active.
#
python script.py

When i try to run it with either “source bashScript.bash” or “bash bashScript.bash” I get the errors: source: No such file or directoryctivate bash: No such file or directory line 2: name_Env/bin/activate and the python configparser error.

The weird thing is that when i type the same thing manually everything works fine but in the bash file not. Is there something wrong in the bash file has it something to do with something else?

(the reason I am using bash file is because I think you cant open a virtualenv in a cronjob but you can link to a file that opens one and runs script)

The directory

/root
	/environments
		bashScript.bash
		script.py
		/random directories
		/name_Env
			/bin
				activate

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.