By Huskerdoggo
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
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Generally, when sourcing a file, you want to use either ./ or the full path, so what I’d recommend is using:
#!/usr/bin/env bash
source ./name_Env/bin/activate
or
#!/usr/bin/env bash
source /root/environments/name_Env/bin/activate
Though you should also be able to use double-quotes around the source file as well.
#!/usr/bin/env bash
source "./name_Env/bin/activate"
or
#!/usr/bin/env bash
source "/root/environments/name_Env/bin/activate"
You could even set the file to a variable:
#!/usr/bin/env bash
readonly sourceFile="./name_Env/bin/activate"
source ${sourceFile}
or
#!/usr/bin/env bash
readonly sourceFile="/root/environments/name_Env/bin/activate"
source ${sourceFile}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.