Search code examples
pythonbashqiime

bash: python: .py: command not found


I am trying to run the following command in QIIME2 virtual machine, installed on macbook but the code is not working

validate_mapping_file.py -m Fasting_Map.txt -o mapping_output

Here is the link: http://qiime.org/tutorials/tutorial.html

I get the following message

bash: validate_mapping_file.py: command not found

I am new to unix/linux as well as on qiime. I would be very thankful for the help...


Solution

  • To execute a Python script in this way, you need three things:

    1. The file needs to have the executable bit set for you. To do this, try using: chmod u+x validate_mapping_file.py

    2. The file needs to begin with a shebang, for example #!/usr/bin/env python3 which will tell the system to run the script using the python3 executable according to your environment

    3. The file needs to be in one of the directories in your PATH environment variable. You can add the current directory using export PATH=$PWD:$PATH or use ./validate_mapping_file.py instead of just validate_mapping_file.py (thanks @Grisha)

    Afterwards you should be able to execute the script the way you tried before.