# Problem with 'Screen' function - PTB just installed

**URL:** <https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451>\
**Category:** Programming Help\
**Tags:** windows\
**Created:** [August 13, 2024, 9:01am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451 "2024-08-13T09:01:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 13, 2024, 9:01am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/1 "2024-08-13T09:01:25Z")

</div>

EEJDHUP7-20248131369:2ebe50a9f3c3fd2ab4d9300f9593b3b4bbd33d2c95b2f4f736b5296314c4c852

Hi,  
I have a problem with the ‘Screen’ function.  
I recently downloaded PTB the ‘Screen’ function gives me the following:  
_Invalid MEX-file ‘C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic\MatlabWindowsFilesR2007a\Screen.mexw64’: The specified module could not be found._  
The file is actually there.

This is my MATLAB version:  
‘24.1.0.2653294 (R2024a) Update 5’

The operating system is:  
Windows 10 Pro

I used ‘vcredist\_x64\_2015-2019.exe’ to install.

I would appreciate your help.

Giorgio

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [August 13, 2024, 9:25am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/2 "2024-08-13T09:25:20Z")

</div>

Did you also install GStreamer (see “help GStreamer”)?

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 13, 2024, 9:44am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/3 "2024-08-13T09:44:14Z")

</div>

Yes, I did.  
‘MinGW 64-bit 1.24.6 runtime installer’

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 13, 2024, 4:38pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/4 "2024-08-13T16:38:03Z")

</div>

That’s the wrong GStreamer flavor. Our docs stress that you must use the MSVC variant, not the MinGW variant. Uninstall that and then install the MSVC variant,  
then retry.

-mario  
[4 minutes out of 30 minutes paid support used up].

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 14, 2024, 11:01am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/5 "2024-08-14T11:01:38Z")

</div>

I guess you mean “then install the **MSVC** variant”.  
I will do it.

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 14, 2024, 11:10am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/6 "2024-08-14T11:10:33Z")

</div>

After rerunning ‘SetupPsychtoolbox’, I saw some progress 🙂

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 14, 2024, 1:52pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/7 "2024-08-14T13:52:38Z")

</div>

Good to hear. So it works now?

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 14, 2024, 3:42pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/8 "2024-08-14T15:42:19Z")

</div>

Yes, thank you very much

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 15, 2024, 12:18pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/9 "2024-08-15T12:18:51Z")

</div>

The problem I have now is that I have to run SetupPsychtoolbox each time I reboot

---

<div class="post-metadata">

**Author:** ![xiangrui](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xiangrui](https://psychtoolbox.discourse.group/u/xiangrui)\
**Post date:** [August 15, 2024, 12:59pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/10 "2024-08-15T12:59:55Z")

</div>

Try to run SetupPsychtoolbox when Matlab is started with Run As Administrator once, and I believe it should work next time.

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 15, 2024, 2:01pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/11 "2024-08-15T14:01:25Z")

</div>

I followed these instructions:  
[https://www.mathworks.com/matlabcentral/answers/344572-how-to-make-a-shortcut-to-always-run-as-administrator](https://www.mathworks.com/matlabcentral/answers/344572-how-to-make-a-shortcut-to-always-run-as-administrator)

_Go to the MATLAB icon_  
_Click on properties_  
_Go to the Shortcut tab_  
_Press Advanced…_  
_Check the “Run as administrator” checkbox._

It didn’t work.

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 15, 2024, 4:27pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/12 "2024-08-15T16:27:47Z")

</div>

Didn’t SetupPsychtoolbox provide you with a helpful message on how to resolve this? It should have?

[7 minutes out of 30 minutes paid support used up].

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 17, 2024, 11:37am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/13 "2024-08-17T11:37:15Z")

</div>

Hi.  
No Mario, I haven’t found anything.  
Even if I ran SetupPsychtoolbox while running Matlab as administrator, I continue having to run SetupPsychtoolbox each time I start a session.  
Any other suggestion?

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 17, 2024, 2:48pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/14 "2024-08-17T14:48:57Z")

</div>

I assume you downloaded the zip file with the latest Psychtoolbox? Or the MLTBX file?

What is the full output of `SetupPsychtoolbox` and PsychtoolboxRoot? What is the output of `which pathdef`?What is the output after quitting and restarting Matlab? What is the output of `which pathdef` after restarting Matlab?

[14 minutes out of 30 minutes paid support used up].

---

<div class="post-metadata">

**Author:** ![gtrumpy](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gtrumpy](https://psychtoolbox.discourse.group/u/gtrumpy)\
**Post date:** [August 19, 2024, 7:57am UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/15 "2024-08-19T07:57:58Z")

</div>

Hi Mario,

I paste here the information you asked.

- PTB-3 version is 3.0.19.14  
Zip was downloaded from here: [GitHub - Psychtoolbox-3/Psychtoolbox-3 at 3.0.19.14](https://github.com/Psychtoolbox-3/Psychtoolbox-3/tree/3.0.19.14)

- After starting MATLAB, I always get this:

_PsychStartup: Adding path of installed GStreamer runtime to library path. [D:\gstreamer\1.0\msvc\_x86\_64\bin]_

- If I run the ‘Screen’ function, I initially get this:

_In place of the expected mex file this placeholder file was executed:_

_Screen_

_This mex file seems to be missing or inaccessible on your Matlab path or it is dysfunctional:_

_Screen.mexw64_

_It is important that the folder which contains the Screen mex file is located before_  
_the PsychBasic folder on your Matlab path._  
_On Matlab V7.4 (R2007a) or later versions, the folder_  
_C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic\MatlabWindowsFilesR2007a\ must be before the folder_  
\*C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic\ \*

_type path to display the current path and check for this condition._  
_If the order is wrong, simply cd into your Psychtoolbox root folder_  
_C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\ and then run SetupPsychtoolbox again._  
_That is the simplest way of fixing such path problems - Or to get more diagnostic output._

_Seems Screen.m is in the Matlab path before/above Screen.mexw64 instead of after/below it!_  
_This will cause the mex file to be ignored, leading to this error._  
_Please run SetupPsychtoolbox again, to rectify this problem, or use Matlabs pathtool_  
_to shuffle things into the right order. This folder:_

_C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic\MatlabWindowsFilesR2007a_

_needs to go above/before this folder:_

_C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic_

_On Microsoft Windows with supported Matlab versions (\>= V7.4) it could also be that_  
_the required Visual C++ 2015-2019 runtime libraries are missing on your system._  
_The Psychtoolbox/PsychContributed/ subfolder contains installer files for them, which_  
_you can execute after quitting Matlab. The name of the file is:_  
_vcredist\_x64\_2015-2019.exe and maybe also vcredist\_x64\_2010.exe._

_NOTE: You may want to acquire paid support for future issues like this._  
_Please type ‘PsychPaidSupportAndServices’ to learn more._

_Error using AssertMex (line 216)_  
_Missing or dysfunctional Psychtoolbox Mex file for this operating system. Read the help text above carefully!!_

_Error in Screen (line 158)_  
_AssertMex(‘Screen.m’);_

- Then I run “SetupPsychtoolbox” as suggested, and I get this:

_Will setup working copy of the Psychtoolbox folder inside: C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox_

_Your old Psychtoolbox appears in the MATLAB/OCTAVE path:_  
_Your old Psychtoolbox appears 1084 times in the MATLAB/OCTAVE path._  
_Before you decide to delete the paths, do you want to see them (yes or no)? n_  
_You didn’t say “yes”, so I’m taking it as no._  
_Shall I delete all those instances from the MATLAB/OCTAVE path (yes or no)? y_  
_Success._

_Now adding the new Psychtoolbox folder (and all its subfolders) to your MATLAB/OCTAVE path._  
_Success._

_Running post-install routine…_

_PsychStartup: Adding path of installed GStreamer runtime to library path. [D:\gstreamer\1.0\msvc\_x86\_64\bin]_  
_Matlab release 2014b or later detected. Will prepend the following_  
_folder to your Matlab path: C:\Users\User1\AppData\Roaming\MathWorks\MATLAB Add-Ons\Collections\Psychtoolbox-3\Psychtoolbox\PsychBasic\MatlabWindowsFilesR2007a\ …_  
_PTB-INFO: Multi-display setup in explicit multi-display mode detected. Using the following mapping:_  
_PTB-INFO: Screen 0 corresponds to the full Windows desktop area. Useful for stereo presentations in stereomode=4 …_  
_PTB-INFO: Screen 1 corresponds to the display area of the monitor with the Windows-internal name \.\DISPLAY1 …_  
_PTB-INFO: Screen 2 corresponds to the display area of the monitor with the Windows-internal name \.\DISPLAY2 …_

\*PTB-INFO: Your version of Matlab 64-Bit is global system DPI aware. On Windows-8 or later, fullscreen onscreen windows will only work \*  
_PTB-INFO: properly timing-wise when displayed on displays with the same pixel density as your systems primary display monitor._  
_PTB-INFO: For your multi-display setup the stimulus display monitor must have a DPI of (144, 144), matching that of_  
_PTB-INFO: your primary display monitor. Ideally you will only display on the primary display in the first place._  
_PTB-INFO: Displaying on anything with a different DPI will cause mysterious visual timing problems, sync failures etc._  
_PTB-INFO: Read ‘help RetinaDisplay’ for more info on this topic._

_Trying to trigger an update of the fontconfig cache if that should prove neccessary._  
_This may take a couple of seconds, or sometimes even minutes. Please be patient…_

_Done with post-installation. Psychtoolbox is ready for use._

_GENERAL LICENSING CONDITIONS AND TERMS OF USE:_  
_----------------bla bla--------------------_

_BEGINNERS READ THIS:_  
_------bla bla---------_

_Enjoy!_

- After doing this, I run the ‘Screen’ function again and it works.

- It is necessary to run “SetupPsychtoolbox” at every new session, irrespective of whether I run MATLAB as Administrator or not.

- “which pathdef” always gives me:  
_C:\Program Files\MATLAB\R2024a\toolbox\local\pathdef.m_

I hope this helps.

Giorgio

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 19, 2024, 2:08pm UTC](https://psychtoolbox.discourse.group/t/problem-with-screen-function-ptb-just-installed/5451/16 "2024-08-19T14:08:11Z")

</div>

Ok, I think I know what happened. You, or someone before you originally installed Psychtoolbox via the Matlab toolbox add-on package via Matlabs Add-On Manager, ie. the file with the .mltbx ending. Iow. the 3.0.19.14.mltbx file instead of the 3.0.19.14.zip file.

The problem with the Matlab add-on manager method is that it adds Psychtoolbox folders in the wrong order, ie. the _MatlabWindowsFilesR2007a_ subfolder after instead of before the PsychBasic folder, so the proper mex files can’t be found. SetupPsychtoolbox fixes this, but Matlab restores the old order and undo’s the fix at every restart. The add-on manager is not the brightest piece of software and I found it buggy in other areas as well, so while it looks like the most convenient way of installing Psychtoolbox, it is actually the most troublesome/clunky way at the moment. That’s why we don’t advertise it on our page with Download instructions. I’m tempted to disable the whole .mltbx download method, but Mathworks wanted us to offer this method for Matlab users, despite it not adding any advantages to the user experience.

I have an idea for how to make it less worse in some future PTB releases, but for now the advice is to avoid that method. Do this:

1. Use the Matlab Add-on manager to completely remove your Psychtoolbox.
2. Download the regular and recommended 3.0.19.14.zip file from currently [https://github.com/Psychtoolbox-3/Psychtoolbox-3/releases/download/3.0.19.14/3.0.19.14.zip](https://github.com/Psychtoolbox-3/Psychtoolbox-3/releases/download/3.0.19.14/3.0.19.14.zip) for the latest current release.
3. Unzip it, cd() into its unzipped Psychtoolbox folder.
4. Run SetupPsychtoolbox again.

After this, the path should persist across restarts of Matlab and things should hopefully work.

-mario  
[32 minutes out of 30 minutes paid support used up - Paid support exhausted].
