NameError: name 'runfile' is not defined

11,389 views
Skip to first unread message

Larry M

unread,
Jun 16, 2013, 8:17:13 AM6/16/13
to spyd...@googlegroups.com
I have been using Spyder on my desktop for about a week and was able to get some small programs running.  Then I started to get an error that says "NameError: name 'runfile' is not defined " whenever I run a script from the editor.  Even the simplest script will do this.  However, when I use "run selection or current block of lines" from Spyder that works.  When I try to use the debugger, I get "NameError: name 'debugfile' is not defined."  I have removed Spyder and Python, and then reinstalled using Python(x,y).  I even tried reinstalling Spyder using Anaconda and WinPython.  Spyder gives the same errors after the reinstalls.  

At the same time this was going on, I used Anaconda to install Spyder on my laptop, and that seems to work fine--the NameErrors do not appear.   It seems that I inadvertently changed something on my desktop that persists after a reinstall.    

Any suggestions?  

Thanks,

Larry

Jed Ludlow

unread,
Jun 17, 2013, 1:28:57 PM6/17/13
to spyd...@googlegroups.com
Hi, Larry.

Kind of a stab in the dark, but make sure that "Path to Python interpreter executable binary" in the "Tools>Preferences>Console>Advanced settings" dialog points to the Python interpreter you want your scripts to be running in. I suspect that would be C:\Python27\python.exe.

Jed

Larry M

unread,
Jun 18, 2013, 1:52:00 PM6/18/13
to spyd...@googlegroups.com
Hi Jed,    Thanks for the reply.  I checked out the path to the .exe and it was set to a version of python.exe installed with winpython.  I downloaded a separate file so I could set it up as you suggested, C:\Python27\python.exe.  Unfortunately, this gives the same error as I described in the original post.  

This error has survived through multiple reinstalls, so it seems like it must be something that persists in Windows after Python and Spyder have been removed.  Any ideas on where to look for this type of thing?   

Thanks for your help.

Larry

Jed Ludlow

unread,
Jun 20, 2013, 11:31:04 AM6/20/13
to spyd...@googlegroups.com
On Tuesday, June 18, 2013 11:52:00 AM UTC-6, Larry M wrote:
Hi Jed,    Thanks for the reply.  I checked out the path to the .exe and it was set to a version of python.exe installed with winpython.  I downloaded a separate file so I could set it up as you suggested, C:\Python27\python.exe.  Unfortunately, this gives the same error as I described in the original post.  

This error has survived through multiple reinstalls, so it seems like it must be something that persists in Windows after Python and Spyder have been removed.  Any ideas on where to look for this type of thing?   

Thanks for your help.


Larry,

Could you try to reset Spyder from the command line by issuing the command spyder --reset at a command prompt? Then try to start Spyder as you normally would.

It sounds like you may have multiple Python distributions installed on your system now. It might be best to focus on getting one of those to work right. Do you have a preference about which distribution you want to use?

Jed

Larry M

unread,
Jun 21, 2013, 11:33:10 AM6/21/13
to spyd...@googlegroups.com
Hi Jed,     I tried the "spyder --reset" from the command prompt when in the same directory as spyder.exe.  This seemed to do something--I could see some files flash by--but ultimately when I restarted spyder the result was the same.  

I currently have WinPython installed and I also tried running spyder (light) from the Winpython directory.  This gave an error message that said I should use the reset command--the same thing you said.  Running spyder from this same directory did not give the error message.  So I did the reset and tried running spyder (light) again.  This time spyder (light) ran, but it has the same problem with "NameError: name 'runfile' is not defined" that I had with regular spyder.    

I only have WinPython installed right now.  I have tried Anaconda, Python(x,y), Python27, and probably some others, but they have all been removed. 

Any other ideas?

Thanks,  

Larry

Uwe Fechner

unread,
Jun 21, 2013, 1:06:35 PM6/21/13
to spyd...@googlegroups.com
Hello,

please try the following from the winpython command prompt:

c:
cd \WinPython-32bit-2.7.3.3
path=""
Spyder.exe

Change the first two lines if your winpython version is installed somewhere else,
or if you have a different version.

If this works, than create a spyder.bat file that contains the lines above.
Than you should be able to launch Spyder with a double-click on the spyder.bat
file.

This workaround is needed if there is still an old python version in your path.

Regards:

Uwe Fechner
> --
> You received this message because you are subscribed to the Google Groups "spyder" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> spyderlib+...@googlegroups.com.
> To post to this group, send email to spyd...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spyderlib.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Larry M

unread,
Jun 22, 2013, 6:48:41 PM6/22/13
to spyd...@googlegroups.com
Hi Uwe,     Thanks for your suggestion.  I made a small change in the folder name to account for the 64 bit version I am using, but otherwise I did what you said.  Spyder started fine from the command prompt.  Unfortunately, the behavior of Spyder is unchanged.  It gives the same NameError when I run a script using "Run file," but I can run the same script successfully using "Run selection or current block of lines."  

Any other ideas?

Thanks again,

Larry


Gbenro Odunaiya

unread,
Jun 22, 2013, 7:05:13 PM6/22/13
to spyd...@googlegroups.com
Another new user who has the same problem. However, what I'm doing to work around it is running in a new interpreter. Go to Tools/Preferences, then choose the "Run" tab and under "Interpreter", select "Execute in a new dedicated Python interpreter".

Hope that helps.

Larry M

unread,
Jun 22, 2013, 10:13:58 PM6/22/13
to spyd...@googlegroups.com
Gbenro,    Thanks for letting me know about the fix.  It worked.   cheers,   Larry

Jed Ludlow

unread,
Jun 23, 2013, 12:06:08 AM6/23/13
to spyd...@googlegroups.com
On Saturday, June 22, 2013 8:13:58 PM UTC-6, Larry M wrote:
Gbenro,    Thanks for letting me know about the fix.  It worked.   cheers,   Larry

Larry,

I'm glad you were at least able to find a workaround. If you are interested in pursuing your previous issue any further, here's another something to try.

From the Spyder Python console, type

import sys
sys.executable

What is the result? How does it compare to what's in Preferences>Editor> Advanced settings>Python executable?
If you are running WinPython, they should both point to something like C:\WinPython-64bit-2.7.5.1\python-2.7.5.amd64

Jed

Larry Murdoch

unread,
Jun 24, 2013, 8:37:37 AM6/24/13
to spyd...@googlegroups.com
Jed,    I changed the settings back to ...Interpreter>execute in current interpreter, because this is the configuration that was causing the problem.  Then I used the commands you said to get 'C:\\winpython\\WinPython-64bit-2.7.5.1\\python-2.7.5.amd64\\python.exe.'  Then I went to     Preferences>Console>Advanced (Console instead of Editor) and the path to python interpreter and executable binary was pointing to the same file, but with single backslash instead of double.  It seems like they are both pointing to the same place.  

I tried switching between Run>Interpreter>execute in current interpreter, and Run>Interpreter>execute in new interpreter, and confirmed that the first setting (current interpreter) gives the NameError error and the second one (new interpreter) is OK.  

Larry 


--
You received this message because you are subscribed to a topic in the Google Groups "spyder" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spyderlib/myEBR_DWnFw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spyderlib+...@googlegroups.com.

Jed Ludlow

unread,
Jun 26, 2013, 1:25:54 AM6/26/13
to spyd...@googlegroups.com


On Monday, June 24, 2013 7:37:37 AM UTC-5, Larry M wrote:
Jed,    I changed the settings back to ...Interpreter>execute in current interpreter, because this is the configuration that was causing the problem.  Then I used the commands you said to get 'C:\\winpython\\WinPython-64bit-2.7.5.1\\python-2.7.5.amd64\\python.exe.'  Then I went to     Preferences>Console>Advanced (Console instead of Editor) and the path to python interpreter and executable binary was pointing to the same file, but with single backslash instead of double.  It seems like they are both pointing to the same place.  

I tried switching between Run>Interpreter>execute in current interpreter, and Run>Interpreter>execute in new interpreter, and confirmed that the first setting (current interpreter) gives the NameError error and the second one (new interpreter) is OK.  

Larry 


It sure sounds like Spyder's sitecustomize.py file is not being completely loaded at interpreter start. Do see any error messages in the interpreter at startup? Something like: 'import sitecustomize' failed; use -v for traceback.

Jed

Terence Lam

unread,
Aug 3, 2013, 10:18:03 AM8/3/13
to spyd...@googlegroups.com
Hi Odunaiya, I tried your suggestion but unfortunately it didnt work for me... Is there other work around? Thanks.

stone...@gmail.com

unread,
Aug 3, 2013, 6:22:57 PM8/3/13
to spyd...@googlegroups.com
Hi,

A small question : when you have the error, does the path to your program include this combination of letters : "\u" ?

kristian...@gmail.com

unread,
Aug 23, 2013, 8:14:30 AM8/23/13
to spyd...@googlegroups.com
The simplest explanation for this type of error is that something in the path has the same name as the intended command. Try clearing everything from the path and try again.

Benjamin Griffel

unread,
Nov 11, 2013, 9:36:05 PM11/11/13
to spyd...@googlegroups.com
I had this same issue and I fixed it by putting the directory
C:\WinPython-64bit-3.3.2.3\python-3.3.2.amd64\Lib\site-packages\spyderlib\widgets\externalshell

into my PYTHONPATH environmental variable.  It seems as thought python could not find the sitecustomize.py file without doing this.  I hope this helps.

Carlos Córdoba

unread,
Nov 13, 2013, 8:08:29 AM11/13/13
to spyd...@googlegroups.com
Thanks a bunch for tracking this down!! I was totally baffled by this
problem. I'll report it with the WinPython guys.

Cheers,
Carlos

El 11/11/13 21:36, Benjamin Griffel escribió:
> --
> You received this message because you are subscribed to the Google
> Groups "spyder" group.
> To unsubscribe from this group and stop receiving emails from it, send

Chaima Amine-khodja

unread,
Nov 20, 2019, 3:46:14 PM11/20/19
to spyder
hello , please  can u help ! i've tried almost all suggestions in here and none of them worked with me , each time i want to excute the code i get this message 


runfile('C:/Users/pcc/Desktop/python/first tries.py', wdir='C:/Users/pcc/Desktop/python')
Traceback (most recent call last):

  File "<ipython-input-3-820c236e72e1>", line 1, in <module>
    runfile('C:/Users/pcc/Desktop/python/first tries.py', wdir='C:/Users/pcc/Desktop/python')

NameError: name 'runfile' is not defined

 please , what should i do !

Le mercredi 13 novembre 2013 14:08:29 UTC+1, Carlos Córdoba a écrit :
Thanks a bunch for tracking this down!! I was totally baffled by this
problem. I'll report it with the WinPython guys.

Cheers,
Carlos

El 11/11/13 21:36, Benjamin Griffel escribió:
> I had this same issue and I fixed it by putting the directory
> C:\WinPython-64bit-3.3.2.3\python-3.3.2.amd64\Lib\site-packages\spyderlib\widgets\externalshell
>
> into my PYTHONPATH environmental variable.  It seems as thought python
> could not find the sitecustomize.py file without doing this.  I hope
> this helps.
> --
> You received this message because you are subscribed to the Google
> Groups "spyder" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to spyd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages