Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 48
Next »
Table of contents
Child pages
- regarding "jobs" (running tasks / programs, analogous to "windows" on a GUI OS):
- List jobs: 'jobs'
- Alt-tab out of a job: 'Ctrl + z'
- Switch to a job: 'fg job_number' (fg is for 'foreground')
- Close / quit a bash console session: "exit". You'll still need to close the browser tab manually, but you won't end up with a longer-and-longer list of unused bash console sessions on your PA home page.
- Get a list of installed virtual environments:
- Start a virtualenv you've already created:
- Quit a virtualenv:
- Remove a virtualenv
- Background
- These need to be set up just right or they won't work, and the error messages won't be very helpful. This can be a huge hassle, so follow the instructions below!
- These instructions will assume you want to run a Python script.
- Step-by-step instructions
- If you're trying to run a very simple script that isn't part of some larger package and doesn't need to run from a virtualenv (to get access to certain modules):
- Follow the instructions here: https://help.pythonanywhere.com/pages/ScheduledTasks/
- If you need to run from a virtualenv but aren't dependent on other modules from some parent package:
- Follow the instructions here: https://help.pythonanywhere.com/pages/VirtualEnvInScheduledTasks
- If you're trying to run a script / module that depends on other modules in some larger package you're working on, and you need to run it from a virtualenv to get access to certain third-party modules it uses:
- Create a new bash script in the directory that contains the parent package that contains the script / module you're interested in.
- I recommend naming the file after the module / function it'll be running.
- Usually that'll be your project directory.
- Example: /home/nathanwailes/project_name/, where there is no __init__.py in the directory, but there is a subfolder that does contain an __init__.py. So the package folder is /home/nathanwailes/project_name/package_name.
- 'project name' vs. 'package name' can be confusing, so just think of it like this: the 'package name' is the thing that other people would import in Python, while the 'project name' is the thing that would be cloned by git / source control.
- Copy the instructions below into the bash script to make it run the Python file.
- Here's an example of what the bash script should look like:
#!/bin/bash
source /home/nathanwailes/.virtualenvs/name_of_the_virtualenv_for_the_project/bin/activate
cd /home/nathanwailes/name_of_the_project/
python -m name_of_the_package.name_of_a_submodule.name_of_the_module_you_want_to_run
deactivate
- Note how the script does a 'cd' into the directory above the parent module. This is necessary for the next command ('python -m') to work properly.
- Note how I don't run the submodule directly, but run 'parent_package.(...).module_name' instead. This is necessary if the module you're trying to run has imports of other modules from the package it is in.
- Example: if the module you're trying to run is 'package_name.module_name', and it has a line that says 'from package_name.other_module import some_function', the only way to get that to work is to run it as 'package_name.module_name' so that Python will know about the other modules in the package.
- Make sure to use 'chmod' to allow your bash script to be executable!
- If you don't, you may see a "Permission denied" error.
- Example:
chmod 755 name_of_the_bash_file.bash