Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop
Because I know this place is littered with coding geeks.
I'm getting the following error
tkinter.TclError: error getting working directory name: not owner
It's on some scripts I wrote a couple of years ago using the turtle function to draw some simple shapes. I recently upgraded to Python 3.10.2 and it's happening with all the scripts, which I know worked fine last time I ran them (a couple of years ago).
I've tried Googling but to no avail. Any ideas?
nope but if anyone can tell me why the google earth engine in qgis no longer works for me i'd be very grateful...
Can you run them as an administrator?
I imagine that the problem is explained in the error message?
Have you checked the permissions on the working directory?
Perhaps you've moved the script since originally writing it?
Can you run them as an administrator?
No something I've ever heard. Is it easy?
I should maybe add that it's a Mac I'm using. In case the operating system is the issue. I presume something in the upgrade is no longer pointing to the correct directory but no idea how I check.
Maybe post the script up somewhere so people can see it? If you were calling a script using the full path, perhaps that path is mo longer correct? But the error does suggest a permissions problem
I tried running this to get the current directory.
import os
directory = os.getcwd()
That gave the following error.
PermissionError: [Errno 1] Operation not permitted
Where are you running the script from?
Running on IDLE.
This is one of the scripts that won't work:-
from turtle import *
color('blue')
shape('turtle')
speed(10)
pensize(4)
forward(50)
right(45)
forward(50)
color('red')
speed(1)
for x in range(4):
forward(50)
right(33)
Sorry, I meant whereabouts in the file system? I'm not a code geek, but I know my way round Linux reasonably well.
Sorry, I meant whereabouts in the file system
How do you find out?
Just tried running that script from the terminal and it's fine there. So issue seems to be IDLE.
Obvious questions - which version of Python were you using before? Were you using IDLE before (same version?)?
If it were me - I would try launching IDLE with sudo to see if it's just a permission issue. I should say that I would do that for code I had written and knew exactly what it was doing - running stuff as sudo/root is generally a bad idea.
I was on version 2.7.18. Now on 3.10.2. Does seem to be a permission problem, but it's only turtle that seems to be a problem. Other scripts are fine.
I was using IDLE before as well and it was fine. Turtle scripts do work when run from the terminal rather than IDLE.
theres a thread on this error in stackoverflow
the solution seems to be
You just need to copy two folders from tcl folder to the Lib folder
tcl8.5 and tk8.5
Klunk may well have the answer. But I've generally found stuff doesn't always go smoothly going from python2.x to 3.x. On the command line are you sure you are using the new version? Often to get python3.x you need to run python3 myscript.py (i.e. you might still be using the old version in terminal vs idle). The hard issues with upgrading for me have been packages you are using and making sure that you are using the correct version of the modules you need (you may need to uninstall turtle and reinstall with pip3 etc.)
Cheers guys, quick, and maybe silly, question. How do I find those files?
Poly, I'll try and check that out. I did think about getting rid of the old version but have heard that's a bad idea with Macs as Python comes preinstalled. IDLE does suggest I'm running the latest version but will check out the turtle reinstall thing.
Could be a number of things - where are the actual programs, on the mac drive or a network/external drive.
You say it works when run from the command line.
How do you run it from the command line ?
What is your current directory - use the 'pwd' command
What is the very first line of the script - does it start with #!<some python version>
When you are running it from the IDE you may be running it with a different python, or even a different working directory - ive never used IDLE so not sure.
macOS has some new permission security full disk access permissions, but I doubt it is that.
The error message implies that the program cannot search backwards from its working directory to the root, so you need to find the working directory, and use the 'ls -l' commands to check you have 'r' and 'x' permissions on them all. If you can run pwd, then thats fine
You say it works when run from the command line.
How do you run it from the command line ?
What is your current directory – use the ‘pwd’ command
What is the very first line of the script – does it start with #!<some python version>
When you are running it from the IDE you may be running it with a different python, or even a different working directory – ive never used IDLE so not sure.
macOS has some new permission security full disk access permissions, but I doubt it is that.
The error message implies that the program cannot search backwards from its working directory to the root, so you need to find the working directory, and use the ‘ls -l’ commands to check you have ‘r’ and ‘x’ permissions on them all. If you can run pwd, then thats fine
To run it from the terminal I just type python3 then ENTER then paste in my code and hit ENTER again. Running from IDLE it does show Python 3.10.2 at the top so presume I'm running the correct version.
Running pwd does work. And checking the current working directory using cwd = os.getcwd() shows it as being the same directory as when I use pwd.
To run it from the terminal I just type python3 then ENTER then paste in my code and hit ENTER again. Running from IDLE it does show Python 3.10.2 at the top so presume I’m running the correct version.
than sounds like you are making life hard for yourself! If the file you run in idle is called "myfile.py" then typing:
python3 myfile.py
should run it. I think
python myfile.py
will run it under your old python 2.x set up too.
you can check the exact version you are using with:
python -V
or
python3 -V
By the way if you do much python stuff you'll probably find moving away from IDLE gives you huge leaps in productivity. Which IDE is best for you will depend what you commonly do.
Cheers poly. I went with IDLE just because that's what came when I downloaded and installed Python. Being a Python novice I just went with the flow so to speak. IDLE has the advantage in that running a script simply involves hitting F5 when I'm in the script itself (all my Python scripts are held in a folder on my computer. I tried that command but the terminal is looking in the wrong place. I get a message saying "can't open file '/Users/kennethpollock/python001.py': [Errno 2] No such file or directory" which is because the python001.py file is in another folder; not sure how to change the file path the computer is searching.
I've checked the version and it's up to date ie 3.10.2.
I don't see Python as a career or anything. It's just one of the ways of keeping my brain active in retirement. I spent my career in IT (I know, you wouldn't believe it would you) but it was all with old legacy systems and writing COBOL, DB2 etc). When I retired I realised I missed the coding part (not the endless meetings and other rubbish) so decided to try my hand at Python. Writing the actual code is fine, it's the infrastructure around it that's very unfamiliar. For example this (from above):-
You just need to copy two folders from tcl folder to the Lib folder
tcl8.5 and tk8.5
Sounds easy enough but I can't find the folders in question, even when viewing the "hidden" files on my computer.
Install the anaconda distribution.
Use the spyder IDE.
Using your IDE, find where the files are stored.
, the full path to the file, it will be eg /Users/you/somefolder/xxx.py
From the command line, change directory to that folder
> cd somefolder
Check the file exists
> ls
Execute the file:
> python ./xxx.py
You can use different versions of python to test what the issue might be
Cheers poly. I went with IDLE just because that’s what came when I downloaded and installed Python. Being a Python novice I just went with the flow so to speak.
Completely understandable, but after an hour in a "serious" IDE you will swear you never want to go back to IDLE!
Like Jambo, I use spyder (having installed anaconda) but its quite a lot of overhead so unless you are doing stuff with Pandas/Numpy/Scipy it might be overkill. The devs in my office seem to use a mixture of different stuff but VSCode (not to be confused with Visual Studio!) would probably be my starting point if I wasn't doing any sciency stuff on my machine.
IDLE has the advantage in that running a script simply involves hitting F5 when I’m in the script itself (all my Python scripts are held in a folder on my computer.
Any IDE should offer you that - but for example good ones will also let you inspect the values in variable etc which is incredibly useful for debugging, autocomplete object names (especially useful to list parameters you should be including), and highlight some syntax errors before you even hit run. In Spyder if you use matplotlib it keeps a history of all your recent graphs - it may do the same for turtle output I've never used that. Very useful when playing around with ideas.
I tried that command but the terminal is looking in the wrong place. I get a message saying “can’t open file ‘/Users/kennethpollock/python001.py’: [Errno 2] No such file or directory” which is because the python001.py file is in another folder; not sure how to change the file path the computer is searching.
so you either need to change the path before you run python e.g.
cd /the/folder/with/python_files
python python001.py
or include the path when you run it:
python /the/folder/with/python_files/python001.py
Thanks for those various replies guys, much appreciated. Will have a play about with those idea and maybe try another IDE. Which is the simplest and easiest to use (for a beginner)?
Expect more "dumb questions" tomorrow (-:
Whooppeeee, think I've found the problem. Running scripts today (and I don't know why I wasn't getting this yesterday) a boxed popped up saying “Python” would like to access files in your Documents folder.
I clicked yes and this seemed to fix everything. That would account for the error message about not being able to get the working directory. Doh, just a dumb thing.
However many thanks again to everyone who took the time to reply and offer advice. Genuinely much appreciated.
I like vscode but it seems a constant battle to get it working without admin rights on my work machines.
Whooppeeee, think I’ve found the problem. Running scripts today (and I don’t know why I wasn’t getting this yesterday) a boxed popped up saying “Python” would like to access files in your Documents folder.
I only saw this thread today, and I was just scrolling through to see if anyone had mentioned that. haloric did, sort of:
macOS has some new permission security full disk access permissions, but I doubt it is that.
It's something new-ish in MacOS that every app now needs permissions to 'see' inside your documents folder, presumably you updated the OS since the last time you used Python.
Anyway, glad you got it sorted.
It’s something new-ish in MacOS that every app now needs permissions to ‘see’ inside your documents folder, presumably you updated the OS since the last time you used Python.
I did. Strange thing is that I wasn't getting the message popping up yesterday (or all this would have been avoided). It just started appearing today. However all's good now.
