Report this

What is the reason for this report?

Running a python script through screen but it involves a virtual environment.

Posted on January 4, 2020

I’m very very new to this. I have never used ubuntu before yesterday. I purchased a droplet through digital ocean and I setup the server. I installed python and all of the needed libraries for the script (it’s a simple twitter bot). I i created all the files inside a virtual environment… I think… I followed this guide. It was very helpful. So, I created these files, two of them. One .txt and one was .py . the Python file would take sentences from the txt file and send them to twitter basically. I am trying to run this script 24/7. I googled around and came across this thread . I was following what the user Mohensen stated, I was testing out my directory and things but I cant seem to access my python file. the path I was testing was: environments/my_env/Quotes.py I tried this and it stated “No such file or directory.” I tested it by adding /bin and /activate (both of them were required to access the files when i created them, I’m not sure why, but I had to type them) and it still did not work.



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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Solved! I saved the files inside of the envrionments directory not the bin directory!

Here is an alternative approach

Step 1: Activate Your Virtual Environment

First, when you created a virtual environment, it should have been done using a command like:

python3 -m venv my_env

This creates a directory (my_env) that contains the environment’s Python binaries, libraries, and scripts. To activate the environment, you would need to run:

source /path/to/my_env/bin/activate

Make sure you’re in the correct directory where the virtual environment is located when you run the above command. If you see (my_env) appear in your terminal prompt, it means the virtual environment is active.

Step 2: Navigate to Your Python Script

Once your virtual environment is active, you should be able to navigate to your script. Assuming your script is stored inside the virtual environment folder, try this:

cd /path/to/my_env

And then list the files to ensure your Python script is there:

ls

If your Quotes.py file is in the correct folder, you’ll see it in the list. You should be able to run the script with:

python Quotes.py

If you’re still getting the “No such file or directory” error, double-check the exact location of Quotes.py by navigating to the directory where it’s stored and verifying the path.

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.