Python Using Databases in Python Our Diary App Doing Data Entry

Justin Noor
Justin Noor
3,692 Points

Using 'chmod +x' 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' shortcut per the video, it works, but I still have to 'cd' all the way into the folder where my file is.

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

Could it be my shebang line?


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

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 59,172 Points

chmod is a linux shell command that operates on a file or directory. The command chmod +x 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 and if it is beneath the current directory, you can "find" it and then run it using this hack:

`find . -name`

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 "".

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

  • cd to the directory
  • PATH=$PATH:`pwd`

Then should execute from the prompt.

Post back if you still have issues or questions.