Python Workshop v4
Python Workshop v4
python myscript.py
Python Python script imports
interpreter Python script other packages
python myscript.py
If the script has a shebang* line, you can also run the script like this:
myscript.py
* Shebang line is the first line of a script to specify path of the interpreter, e.g. “#!/usr/bin/python3.9.6”;
** In Linux, file extension like “.py” is ignored. It is the “Shebang” line that defines the type of a script.
In Linux, it is the Shebang line that defines the script type.
import deeptools.misc
In Linux, the Shebang line
if __name__ == "__main__":
args = None define the script type,
if len(sys.argv) == 1: whether it is a Python, R,
args = ["--help"] Perl, or shell script.
main(args)
&
which python
python -V
Python /usr/bin/python3.6
Alias (symbolic link): /usr/local/bin/python
Pip /usr/bin/pip3.6
Alias (symbolic link): /usr/local/bin/pip
If you run “pip install”, you will get an error message “permission denied”. You need
to run “pip install --user” which would install python packages under your home
directory.
When running a script, Python looks for packages from three
different places, and following this order. The first found is used.
sys.path
• Each python installation has its own unique sys.path.
e.g. /usr/lib/python3.6
Install python software with Pip
sys.path
pip install deepTools e.g. /usr/lib/python3.6
# you need write permission to the
sys.path.
/usr/bin
Python, pip and other
/usr/lib executables go here
bin
etc
lib
Python packages
/home/qs24/ go here
miniconda3 etc
/usr/bin
Each software can have its
own isolated environment.
/usr/lib
bin
etc
lib
binPython3.6
$HOME/
etc
env_1 lib
miniconda3 etc
env_2
envs bin Python3.9
env_3 lib
etc
env_n
Each Conda environment has its own python, libraries
and companion pip
Install Conda
python packages in base
pip Install Conda
packages in a
Conda python environment
base pip
python
pip
Install softwere in Conda base vs Conda environment
Name of Conda channel. It is Name of the environment you Name of the Conda package.
the place where conda find will create. It can be any This name must exists in the
the package name. channel.
Activate/deactivate a Conda environment
Activate De-activate
#activate conda base
source ~/miniconda/bin/activate conda deactivate
#activate an environment
conda activate busco
or
#activate conda base
source ~/miniconda/bin/activate busco
During Conda installation, it tries to trick you to make conda activated by default. Don’t do
that!!! If you have already done that, disable it by modifying .bashrc file.
Within a conda environment, you can run either
“conda install” or “pip install”.
Use mamba:
mamba install …
mamba create …
3. You are using a wrong version of Python modules. You need to re-install the right version.
pip install theModuleName==3.12
* When running into version issue, it is better to do it within a Conda environment, to
avoid interference with other software.
If you installed the right version, but still got error message. You need to
verify which python module is actually being used
Python follows this order to find a library
• System default
You are in Conda base, but try to run
• Conda base
a Python script installed by BioHPC
• Conda environment admin.
http://cbsum1c2b010.biohpc.cornell.edu:8009
• Port 80
http daemon 1 • Protocol: http
8009: port
• A ‘daemon’ is a software process that is continuously
running in a background, often listening to a port;
User 1 cbsum1c2b010
Cbsum1c2b010:8009
jupyter daemon 1
8009
ssh daemon
User 2 22
Cbsum1c2b010:8010
jupyter daemon 2
8010
rstudio daemon
8015
User 3
export PYTHONPATH=/programs/jupyter3/lib/python3.6/site-
packages:/programs/jupyter3/lib64/python3.6/site-packages
export PATH=/programs/jupyter3/bin:$PATH
You will be provided with a URL which you can open in a web browser:
http://cbsum1c2b010.biohpc.cornell.edu:8017/?token=dfe3b002ca2d7721c4a2c0c641de91645e74f59d6519e31b
screen
Installation directory:
Pip: sys.path or ~/.local (--user option)
Why is it so complicated?
Because a server is shared by many people and many
applications. To work peacefully together, we have to follow
certain rules.