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 Using Databases in Python Our Diary App Doing Data Entry

Justin Noor
Justin Noor
3,692 Points

Using 'chmod +x diary.py' outside of Treehouse workspaces.

I am on Linux Ubuntu 16.04 and I am not using Treehouse workspaces for my work. I save everything into my own folders using sublime text. I created a virtualenv called 'python35_env' for my Treehouse projects (actually a conda env).

When I use the 'chmod +x diary.py' shortcut per the video, it works, but I still have to 'cd' all the way into the folder where my diary.py file is.

How do you use this shortcut with virtual environments? Assuming that the virtualenv is activated, is 'chmod +x diary.py' supposed to find diary.py regardless of where you are in the directory tree?

Could it be my shebang line?

!/home/anaconda3/envs/python35_env/bin/python

Cheo R
Cheo R
37,150 Points

If all else fails, you can always set up an alias command: How to Use Aliases to Customize Ubuntu Commands

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

chmod is a linux shell command that operates on a file or directory. The command chmod +x diary.py will look only in the current working directory where the command was run. This is a Linux feature and is unrelated to virtualenvs. Keep in mind that virtualenvs do not change the directory structure, it only change the search path for looking for executable files. This is mainly for programs installed using pip. It does not add working directories to the execution search path.

It is not uncommon to cd to the directory containing the python file before trying to run it.

If you don't want to cd to the directory containing the file diary.py and if it is beneath the current directory, you can "find" it and then run it using this hack:

`find . -name diary.py`

Note the backticks are required. They tell the Linux shell to execute the command within the backticks, then use the result as an argument for the shell. find returns a list of files matching the search parameters. In this case, files that have the name "dairy.py".

If you wish to add the diary.py directory to the path for the current shell window (for bash shell):

  • cd to the diary.py directory
  • PATH=$PATH:`pwd`

Then diary.py should execute from the prompt.

Post back if you still have issues or questions.