Using Python in CBS remote access environment
Some tips for using Python in CBS remote access environment (RA).
Current Python environment
It is impossible to install packages yourself inside the CBS RA since it’s cut off from the external Internet. One need to prepare a requirements file, and then CBS installs the environment based on it. To see which packages and versions are installed in the current Python environment in our project in RA, you can download the requirements file by right-clicking and selecting “Save As…” on this link. The Python version is 3.10. This environment will be automatically activated when you load Python prompt (see instructions below) - you don’t have to activate it.
If you need other packages, please create a new requirements file following instructions below and send it to us. It is possible to install several different environments (then you’ll need to activate and deactivate them using ‘conda deactivate’ and ‘conda activate env’ commands in Python prompt).
How to create Python environment
You need to create the environment outside the RA, in Python on Windows, using Mambaforge installed in C:\mambaforge. Follow the steps below to generate a txt file and send it to us. NOTE: if you want to use Jupyter Notebook or Spyder, you need to install them in the environment as well.
On your own Windows system in Python, create a new environment named after the project code (9469) plus your 4-letter RA username and activate it. As an example, we use 9469user.
conda create –n 9469user
conda activate 9469user
Install pip.
conda install pip
Then, install the required packages with pip.
pip install package_name
Export the environment with pip.
pip freeze > C:\temp\environment0000user.txt
- Check that the file does not contain references to local paths (‘file://’).
- If it does, use the following command:
pip list --format=freeze > C:\\temp\\environment0000user.txt
Test the environment by removing and recreating it.
rd /q /s <path to python>\envs\0000user
conda create –n 0000user
conda activate 0000user
conda install pip
pip install –r C:\temp\environment0000user.txt
Now test the Python environment.
How to start Jupyter Notebook in RA
In the search bar, type Python prompt and open it. Then run the command below (sometimes it only works without quotation marks around H:\
). It will open Jupyter Notebook. Change drive (e.g., to F:) if you want to access another drive.
C:\mambaforge\envs\9469\Scripts\jupyter-notebook.exe --notebook-dir="H:\"
Photo by Nastya Dulhiier on Unsplash