Skip to content

Commit

Permalink
Merge pull request psychopy#6743 from larsoner/doc
Browse files Browse the repository at this point in the history
DOC: Document Linux better and tee output
  • Loading branch information
peircej committed Jul 25, 2024
2 parents 2ac2757 + fcbc442 commit cecbd49
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
40 changes: 29 additions & 11 deletions docs/source/download.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,56 @@ On a MacOS machine, `brew` can be used to install |PsychoPy|::
Linux
~~~~~~~~~~~~~~~~~

We are aware that the procedure for installing on Linux is often rather painful.
We are aware that the procedure for installing on Linux is often rather painful.
This is not the platform that the core PsychoPy developers currently use so support
is less good than on some platforms. Feel free to jump in and help improve it as a
contributor! :-)
contributor! :-)

There used to be neurodebian and Gentoo packages for |PsychoPy| but these are both
badly outdated. We'd recommend you do:
badly outdated. We'd recommend you first make sure you have a compatible Python
version installed (currently ``>=3.8, <3.11``). If you need an older version, you
can on Ubuntu for example do:

.. code-block:: bash
# with --no-deps flag if you want to install dependencies manually
pip install psychopy
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10-venv python3.10-dev
python3.10 -m venv path/to/new/psychopyenv # choose a path of interest!
source path/to/new/psychopyenv/bin/activate
**Then fetch a wxPython wheel** for your platform from:
Once you have a compatible Python activated, **copy the link to a wxPython wheel** for
your platform from:

https://extras.wxpython.org/wxPython4/extras/linux/gtk3/

and having downloaded the right wheel you can then install it with something like:

.. code-block:: bash
pip install path/to/your/wxpython.whl
pip install https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/wxPython-4.2.1-cp310-cp310-linux_x86_64.whl
wxPython>4.0 and doesn't have universal wheels yet which is why you have to
``wxPython>=4.0`` doesn't have universal wheels yet which is why you have to
find and install the correct wheel for your particular flavor of linux.
If a wheel is not yet available for your platform (e.g., a new version of Linux),
you will have to build it manually. For example, you can use ``pip download wxPython``,
extract the archive, enter the directory, and try ``python setup.py bdist_wheel`` to
build a wheel yourself. You will likely need to install some system build dependencies.
Once it builds, you can install for example with ``pip install dist/wxPython*.whl``.

For some reasons wxPython (wx.html2) is using an older version of libwebkitgtk
e.g. psychopy will not show up
to fix this (of our own risk):
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main universe'
sudo apt install -t bionic libwebkitgtk-1.0-0

Finally, you can do:

.. code-block:: bash
# with --no-deps flag if you want to install dependencies manually
pip install psychopy
**Building Python PsychToolbox bindings:**

The PsychToolbox bindings for Python provide superior timing for sounds and
Expand All @@ -160,14 +178,14 @@ as needed:
Anaconda and Miniconda
~~~~~~~~~~~~~~~~~~~~~~

Support for conda was contributed and is badly outdated but you may be able to
get it working using `pip install` within your conda environment.
Support for conda was contributed and is badly outdated but you may be able to
get it working using `pip install` within your conda environment.

Generally we recommend you use StandalonePsychoPy instead, for experiment creation,
as an entirely separate app, and use your conda installation for other (e.g. analysis)
scripts.

Alternatively if someone wants to jump in and get things working here again that
Alternatively if someone wants to jump in and get things working here again that
would be appreciated by other users I'm sure.

.. _developers_install:
Expand Down
32 changes: 27 additions & 5 deletions psychopy/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@
REQUIRES_RESTART = False


# Adapted from
# https://code.activestate.com/recipes/580767-unix-tee-like-functionality-via-a-python-class/
# (BSD 3-Clause)
class _Tee(object):
def __init__(self, fid):
self._other_fid = fid

def write(self, s):
sys.__stdout__.write(s)
self._other_fid.write(s)

def writeln(self, s):
self.write(s + '\n')

def close(self):
self._other_fid.close()

def flush(self):
self._other_fid.flush()
sys.__stdout__.flush()


def startApp(showSplash=True, testMode=False, safeMode=False, startView=None):
"""Start the PsychoPy GUI.
Expand Down Expand Up @@ -88,7 +110,7 @@ def startApp(showSplash=True, testMode=False, safeMode=False, startView=None):

# NOTE - messages and errors cropping up before this point will go to
# console, afterwards to 'last_app_load.log'.
sys.stderr = sys.stdout = lastRunLog # redirect output to file
sys.stderr = sys.stdout = _Tee(lastRunLog) # redirect output to file

# Create the application instance which starts loading it.
# If `testMode==True`, all messages and errors (i.e. exceptions) will log to
Expand Down Expand Up @@ -148,7 +170,7 @@ def restartApp():
"""Restart the PsychoPy application instance.
This will write a file named '.restart' to the user preferences directory
and quit the application. The presence of this file will indicate to the
and quit the application. The presence of this file will indicate to the
launcher parent process that the app should restart.
The app restarts with the same arguments as the original launch. This is
Expand All @@ -160,11 +182,11 @@ def restartApp():
"""
if not isAppStarted():
return

# write a restart file to the user preferences directory
from psychopy.preferences import prefs
restartFilePath = os.path.join(prefs.paths['userPrefsDir'], '.restart')

with open(restartFilePath, 'w') as restartFile:
restartFile.write('') # empty file

Expand Down Expand Up @@ -288,7 +310,7 @@ def getAppFrame(frameName):
_psychopyAppInstance.showRunner()
else:
raise AttributeError('Cannot load frame. Method not available.')

frameRef = getattr(_psychopyAppInstance, frameName, None)

return frameRef
Expand Down

0 comments on commit cecbd49

Please sign in to comment.