Python: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 22: Line 22:


<!--T:6-->
<!--T:6-->
You can then load the version of your choice using <tt>module load</tt>. For example, to load Python 3.10 you can use the command
You can then load the version of your choice using <code>module load</code>. For example, to load Python 3.10 you can use the command
{{Command|module load python/3.10}}
{{Command|module load python/3.10}}


Line 85: Line 85:


<!--T:9-->
<!--T:9-->
To create a virtual environment, make sure you have selected a Python version with <tt>module load python</tt> as shown above in section ''Loading a Python module''.  If you expect to use any of the packages listed in section ''SciPy stack'' above, also run <tt>module load scipy-stack</tt>.  Then enter the following command, where <tt>ENV</tt> is the name of the directory for your new environment:
To create a virtual environment, make sure you have selected a Python version with <code>module load python</code> as shown above in section ''Loading a Python module''.  If you expect to use any of the packages listed in section ''SciPy stack'' above, also run <code>module load scipy-stack</code>.  Then enter the following command, where <code>ENV</code> is the name of the directory for your new environment:
{{Command|virtualenv --no-download ENV}}
{{Command|virtualenv --no-download ENV}}


Line 93: Line 93:


<!--T:44-->
<!--T:44-->
You should also upgrade <tt>pip</tt> in the environment:
You should also upgrade <code>pip</code> in the environment:
{{Command|pip install --no-index --upgrade pip}}
{{Command|pip install --no-index --upgrade pip}}


<!--T:12-->
<!--T:12-->
To exit the virtual environment, simply enter the command <tt>deactivate</tt>:
To exit the virtual environment, simply enter the command <code>deactivate</code>:
{{Command|prompt=(ENV) [name@server ~]|deactivate}}
{{Command|prompt=(ENV) [name@server ~]|deactivate}}


<!--T:71-->
<!--T:71-->
You can now use the same virtual environment over and over again.  Each time:
You can now use the same virtual environment over and over again.  Each time:
# Load the same environment modules that you loaded when you created the virtual environment, e.g. <tt>module load python scipy-stack</tt>
# Load the same environment modules that you loaded when you created the virtual environment, e.g. <code>module load python scipy-stack</code>
# Activate the environment, <tt>source ENV/bin/activate</tt>
# Activate the environment, <code>source ENV/bin/activate</code>


=== Installing packages === <!--T:13-->
=== Installing packages === <!--T:13-->
Line 111: Line 111:


<!--T:15-->
<!--T:15-->
All of <tt>pip</tt>'s commands are explained in detail in the [https://pip.pypa.io/en/stable/user_guide/ user guide]. We will cover only the most important commands and use the [http://numpy.scipy.org/ Numpy] package as an example.
All of <code>pip</code>'s commands are explained in detail in the [https://pip.pypa.io/en/stable/user_guide/ user guide]. We will cover only the most important commands and use the [http://numpy.scipy.org/ Numpy] package as an example.


<!--T:16-->
<!--T:16-->
Line 118: Line 118:


<!--T:18-->
<!--T:18-->
We then activate the virtual environment, previously created using the <tt>virtualenv</tt> command:
We then activate the virtual environment, previously created using the <code>virtualenv</code> command:
{{Command|source ENV/bin/activate}}
{{Command|source ENV/bin/activate}}
Finally, we install the latest stable version of Numpy:
Finally, we install the latest stable version of Numpy:
rsnt_translations
56,420

edits