Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIain Simmons
Treehouse Moderator 32,305 PointsPython Shebang not working in Workspaces
After adding the following to diary.py
:
#!/usr/bin/env python3
... and running the following in the console of Workspaces:
chmod +x diary.py
./diary.py
... I get the following error:
: No such file or directory
I'm running a local copy of the Python script on my Windows machine with no problems...
Any ideas Kenneth Love?
4 Answers
Jim Hoskins
Treehouse Guest TeacherHi Iain Simmons
After a bit of head scratching, I think we know what is going on. It looks like the files in your workspace were created in Windows, and uploaded into the workspace. Whatever editor you used was set to use Windows style line endings (AKA "\r\n" or "CRLF"). This causes a problem when trying to run the files on linux, because the shebang line can't have a carriage return (the "\r" or CR in CRLF).
Workspaces itself is maintaining the Windows style line endings of your existing file, but if you create a new file in the workspace, and copy + paste into the new file, that will work.
This is a problem you are likely to encounter if you develop on Windows, and run your code on linux. You want to make sure any editor you use is set to use Unix style line endings.
I hope that helps. If you need help setting up your editor, post what you are using and I'm sure we can find the right settings.
Jim
Iain Simmons
Treehouse Moderator 32,305 PointsThanks Kenneth Love and Jim Hoskins!
Copying and pasting within Workspaces didn't work (I guess it's still holding on to those Windows style line endings!).
Running this command in the console fixed it:
sed -i 's/\r//g' diary.py
Alternatively, you guys could install the dos2unix package in Workspaces and then add the command to the teacher's notes...
Iain Simmons
Treehouse Moderator 32,305 PointsOh and for anyone else using Sublime Text, add this to your user settings to avoid this problem of copying and pasting Windows style line endings:
"default_line_ending": "unix"
Austin David
6,516 PointsJust tried Iain's command in the console and it worked. I've only been using Workspaces thus far.
Mario Blokland
19,750 PointsI have the same problem though. I did this lesson on my Windows machine but have only used the workspace and I get the same error message. Luckily the command which Iain posted helped out :-)
Dave Leigh
8,640 PointsYeah, this impacted me as well and I only used the workspace editor. While I could run the script by passing it to the interpreter directly, I couldn't just "./" it without getting that error message, until after running the sed one-liner.
Kenneth Love
Treehouse Guest TeacherStrange. I did it during the course (as you saw) and just did it just now to make sure it still worked.
Any ideas, Jim Hoskins ?
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 PointsSo I thought I'd test this out on my Raspberry Pi to see what was going on, and I got the same error if I tried to run it with
./diary.py
without first running it withpython3 diary.py
. Maybe it was complaining that thediary.db
file didn't exist?In any case, it still doesn't work in Workspaces. I even tried changing the owner from
nobody:nogroup
totreehouse:users
withchown
, no luck.Same issue if I try and add the shebang to the
students.py
file...