1

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

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Muhammad Arslan
  • 35
  • 1
  • 1
  • 5
  • `chmod +x validate_mapping_file.py` plus please show the first line of this Python file - does it have a shabang line? – Grisha Nov 22 '17 at 21:16
  • Did you try using `./validate_mapping_file.py` or ` to validate_mapping_file.py` – isank-a Nov 22 '17 at 21:30

1 Answers1

10

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.

Florian Rhiem
  • 1,758
  • 1
  • 14
  • 23
  • 1
    ... plus it has to be in one of the `PATH` directories – Grisha Nov 22 '17 at 21:21
  • 2
    ```$(pwd):$PATH```, or its backtick-based equivalent, is extremely inefficient compared to `$PWD/$PATH`; like any other command substitution, it forks a subshell. – Charles Duffy Nov 25 '17 at 01:07
  • @CharlesDuffy I doubt that he types faster than `pwd` executes. Still, it achieves the same and is more efficient, so I editted the answer. – Florian Rhiem Nov 25 '17 at 06:02
  • 2
    @FlorianRhiem, thank you. The concern isn't so much immediate interactive use, but not teaching practices that would create a bottleneck if used in other circumstances (ie. inside an inner loop). – Charles Duffy Nov 25 '17 at 14:18
  • And you need to have Python installed. – Jordan Jul 17 '22 at 11:29