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 trial

Python

Running scripts in workspaces from inside folders?

Thought I would go ahead and organize my Python workspace, so I created folders for each track and dropped the project files in accordingly. This has had some unintended consequences.

Before I was using the following command to run a script from the workspace console.

python filename.py

Now I am getting the following error every time I try.

[Errno 2] No such file or directory

What command do I use to navigate down into the file structure to run a script inside a folder?

Thanks for the help!

2 Answers

Navigating inside a folder is done with the cd (change directory) command.

Here are some examples:

# Navigate to a folder called dir
cd dir

# Navigate back "up" the folder structure
cd ..

It's worth noting though that you can actually run a Python script from a folder without navigating into the folder, by simply specifying the name of the folder followed by a / and then the name of the script.

For example if the folder was named dir and the script was named example.py you could run it with the following command:

python dir/example.py

The console you get access to in the workspace is a locked down version of a Bash shell, which is also what is used on Linux and Mac OS. If you want to learn how to use it properly I would recommend taking a look at the Console Foundations course.

Thanks for the help andren. I had managed to find an article with instructions on how to use the cd command inside the terminal, but it failed to mention the syntax for a filename with a space in it.

Managed to figure that out after using the dir command as you suggested.