Difference between revisions of "Python"

From TSG Doc
Jump to navigation Jump to search
Line 12: Line 12:
 
| latest preview version =  
 
| latest preview version =  
 
| latest preview date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
 
| latest preview date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| installed version      = 2.7.9
+
| installed version      = 3.7.9 64-bits
 
| installed version date = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
 
| installed version date = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
 
| status                = Active
 
| status                = Active
Line 25: Line 25:
 
       | [[Workshop: Python for behavioural scientists|Python for behavioural scientists]]
 
       | [[Workshop: Python for behavioural scientists|Python for behavioural scientists]]
 
   }}
 
   }}
  }}
+
  }}
 
 
 
}}
 
}}
  
[[wikipedia:Python_(programming_language)|Python]] is a general-purpose, high-level programming language. It is also a [[wikipedia:Python_%28genus%29|type of snake]] and it is also a [[wikipedia:Python_%28Efteling%29|rollercoaster]], but one is arguably more relevant to your research than the others.
+
[[wikipedia:Python_(programming_language)|Python]] is a general-purpose, high-level programming language. It is also a [[wikipedia:Python_%28genus%29|type of snake]] and a [[wikipedia:Python_%28Efteling%29|rollercoaster]], but one is arguably more relevant to your research than the others. <br/>
 +
On the lab computers, there is support for Spyder, PyCharm and Psychopy.  
  
 
<!-- Table of Contents will be generated here -->
 
<!-- Table of Contents will be generated here -->
  
'''Python on the labcomputers'''
+
==Upgrade from 2.7 to 3.7==
Since Python version 2.7 has reached end of life since January first 2020, this version is no longer installed on the PCs in the labs. Standard is now: Python 3.7 64-bits.
+
Since Python version 2.7 has reached end of life since January first 2020, this version is no longer installed on our [[System Image]]. Standard is now: Python 3.7 64-bits.
 
If you still have scripts written in Python2, the scripts should be upgraded to Python 3. Most changes are probably the print statements. Print statements should always have parentheses: print('some text')
 
If you still have scripts written in Python2, the scripts should be upgraded to Python 3. Most changes are probably the print statements. Print statements should always have parentheses: print('some text')
 
Key differences between Python 2 and Python 3 are here: https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
 
Key differences between Python 2 and Python 3 are here: https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
  
 +
For our previous documentation for Python 2.7, see [[Python/Legacy]]
 +
 +
==Psychopy==
 
Psychopy 2020.2.10 has been installed in the root of the Python3.7 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop.
 
Psychopy 2020.2.10 has been installed in the root of the Python3.7 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop.
There is also a Psychopy 2020.2.10 installed on Python3.6 32-bits. This version has its own icon on the desktop and should be used when you are using a TOBII Eyetracker.
+
There is also a Psychopy 2020.2.10 installed on Python3.6 32-bits. This version has its own icon on the desktop and should be used when you are using a [[Tobii Eye Tracker]].
 
   
 
   
When your script fails to load in Psychopy, because you need packages that are not installed on our labcomputers, please contact TSG.
+
When your script fails to load in Psychopy, because you need packages that are not installed on our lab computers, please contact TSG.
 
 
On the labcomputer, there is support for Spyder, PyCharm and Psychopy.
 
 
 
'''The information below is outdated'''
 
 
 
 
 
==Installation==
 
 
 
===Windows (32 bit)===
 
# Download the '''[https://www.python.org/downloads/ Win32 installer]'''
 
# Double-click on the executable and follow the steps on your screen.
 
 
 
==Configuration==
 
=== Windows Environment Variables ===
 
<pre>Computer --> Properties --> Advanced settings --> Environment Variables.</pre>
 
 
 
[[image:python_env.jpg]]
 
 
Add the following Path:
 
 
<pre>C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;</pre>
 
 
 
[[image:python_path.jpg]]
 
 
 
[[image:python_path2.jpg]]
 
 
 
===Package Management===
 
 
 
==== pip ====
 
After Python is installed, you can use [[wikipedia:Pip_(package_manager)|pip]] to install your required packages. '''pip is included with Python 2.7.9 or greater'''. For older versions, use the following steps to install:
 
 
 
# Download [https://raw.github.com/pypa/pip/master/contrib/get-pip.py get-pip.py]
 
# Execute get-pip by entering the following command: <code style="background-color:#000; color:#fff; padding:1px 3px;">python get-pip.py</code>
 
 
 
To install a package, simply execute the following command: <code style="background-color:#000; color:#fff; padding:1px 3px;">c:\pip install PACKAGE_NAME</code><br/>
 
Replace PACKAGE_NAME with the name of the package of choice.
 
 
 
'''Note:''' By default, packages are installed in the following folder (Windows):
 
<pre>C:\Python27\Lib\site-packages</pre>
 
This location may differ if you have installed Python somewhere else.
 
 
 
==== Setuptools ====
 
For package management with setuptools, install setuptools using the following command: <code style="background-color:#000; color:#fff; padding:1px 3px;">pip install -U setuptools</code>
 
 
 
To install a package, simply execute the following command: <code style="background-color:#000; color:#fff; padding:1px 3px;">c:\easy_install PACKAGE_NAME</code><br/>
 
Replace PACKAGE_NAME with the name of the package of choice.
 
 
 
===List of Python Packages===
 
{| class="wikitable"
 
|-
 
! Python Library 
 
! Description
 
! Installed
 
! Installer Type
 
! URL
 
|-
 
| PIL || Python Image Library || style="background-color:#9F9;" | Yes || Package Manager || http://www.pythonware.com/products/pil/ 
 
|-
 
| SciPy || Python-based ecosystem of open-source software for mathematics, science, and engineering. || style="background-color:#9F9;" | Yes || Package Manager || http://www.scipy.org/install.html
 
|-
 
| PyWin32 || Python Extensions for Windows || style="background-color:#9F9;" | Yes || Windows Installer || http://sourceforge.net/projects/pywin32/files/pywin32/
 
|-
 
| PySerial || Serial access for Python || style="background-color:#9F9;" | Yes || Windows Installer || https://pypi.python.org/pypi/pyserial
 
|-
 
| wxPython || GUI Toolkit for Python || style="background-color:#9F9;" | Yes || Windows Installer || http://www.wxpython.org/download.php#msw
 
|-
 
| matplotlib || 2D plotting library for Python || style="background-color:#9F9;" | Yes || Windows Installer  || http://matplotlib.org/downloads.html
 
|-
 
| pyo || dedicated Python module for digital signal processing || style="background-color:#9F9;" | Yes || Windows Installer || http://ajaxsoundstudio.com/software/pyo/
 
|-
 
| Opencv2 || Open Source Computer Vision is a library of programming functions mainly aimed at real-time computer vision || style="background-color:#9F9;" | Yes || Windows Installer || http://opencv.org/
 
|-
 
| PyQt ||  Python binding of the cross-platform GUI toolkit Qt || style="background-color:#9F9;" | Yes || Windows Installer || http://www.riverbankcomputing.co.uk/software/pyqt/download5
 
|-
 
| PyQtGraph || Scientific Graphics and GUI Library for Python || style="background-color:#9F9;" | Yes || Windows Installer || http://www.pyqtgraph.org/
 
|-
 
| LXML || library for processing XML and HTML in the Python language || style="background-color:#9F9;" | Yes  || Package Manager || http://lxml.de/
 
|-
 
| PyGame || Pygame is a set of Python modules designed for writing games. || style="background-color:#9F9;" | Yes  || Windows installer || http://pygame.org/news.html
 
|-
 
| PANDAS || Python Data Analysis Library || style="background-color:#9F9;" | Yes  || Package Manager || http://pandas.pydata.org/
 
|-
 
| Expyriment || A Python library for congnitive and neuroscientific experiments. || style="background-color:#9F9;" | Yes  || Package Manager || http://www.expyriment.org/
 
|-
 
| Pyparse || Parse text files in an easier and more maintainable manner || style="background-color:#9F9;" | Yes  || Package Manager || https://pypi.python.org/pypi/PyParse/1.1.7
 
|-
 
| AVbin || media decoding/decompression library || style="background-color:#9F9;" | Yes || Windows Installer || https://code.google.com/p/avbin/
 
|-
 
| Pyglet || a cross-platform windowing and multimedia library for Python. || style="background-color:#9F9;" | Yes  || Manual Install || [[File:Pyglet-1.1.4.zip]]
 
|-
 
| FreeType || Library to Render Fonts || style="background-color:#9F9;" | Yes  || Manual Install || [[file:freetype.zip]]
 
|-
 
| Psignifit || || || ||
 
|-
 
| Psychopy || Psychology Software in Python || style="background-color:#9F9;" | Yes  || Package Manager || http://www.psychopy.org
 
|}
 
 
 
For Psychopy dependancies, check the [[Psychopy]] page.
 
 
 
=== Windows Handlers ===
 
Check the Handlers by opening the Windows registry editor.
 
<syntaxhighlight lang="reg" overflow:auto;">
 
 
 
Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
 
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
 
 
 
Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
 
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
 
 
 
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.CompiledFile\shell\open\command]
 
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
 
 
 
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell\open\command]
 
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
 
 
 
</syntaxhighlight>
 
 
 
 
 
=== Python DLL Files ===
 
 
 
* '''C:\Python27\DLLs\'''
 
* Path Within the script.
 
* '''C:\Windows\System32''' or
 
* '''C:\Windows\SysWOW64'''
 
 
 
== Usage ==
 
 
 
===Example: TestArgs.py===
 
Execute the following script within the commandline (CMD): <code style="background-color:#000; color:#fff; padding:1px 3px;">python testArgs.py a.</code><br/>
 
You should see the following result:
 
 
 
<syntaxhighlight lang="matlab" overflow:auto;">
 
number of argument:  2
 
argv[0]: ./testArgs.py
 
argv[1]: a
 
</syntaxhighlight>
 
  
 
==See Also==
 
==See Also==
Line 187: Line 50:
 
*[[Workshop: Python for social scientists]]
 
*[[Workshop: Python for social scientists]]
 
<!--
 
<!--
*[[Workshop: Python for behavioural scientists]]
 
 
  ==References==
 
  ==References==
 
<references /> -->
 
<references /> -->

Revision as of 18:58, 21 January 2021

Python
Python(tm)
Installed version3.7.9 64-bits
Development statusActive
Written inPython
Websitepython.org

Python is a general-purpose, high-level programming language. It is also a type of snake and a rollercoaster, but one is arguably more relevant to your research than the others.
On the lab computers, there is support for Spyder, PyCharm and Psychopy.


Upgrade from 2.7 to 3.7

Since Python version 2.7 has reached end of life since January first 2020, this version is no longer installed on our System Image. Standard is now: Python 3.7 64-bits. If you still have scripts written in Python2, the scripts should be upgraded to Python 3. Most changes are probably the print statements. Print statements should always have parentheses: print('some text') Key differences between Python 2 and Python 3 are here: https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

For our previous documentation for Python 2.7, see Python/Legacy

Psychopy

Psychopy 2020.2.10 has been installed in the root of the Python3.7 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop. There is also a Psychopy 2020.2.10 installed on Python3.6 32-bits. This version has its own icon on the desktop and should be used when you are using a Tobii Eye Tracker.

When your script fails to load in Psychopy, because you need packages that are not installed on our lab computers, please contact TSG.

See Also

External Links