2

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

2
  • chmod +x validate_mapping_file.py plus please show the first line of this Python file - does it have a shabang line? Commented Nov 22, 2017 at 21:16
  • Did you try using ./validate_mapping_file.py or <absolute_path> to validate_mapping_file.py Commented Nov 22, 2017 at 21:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

... plus it has to be in one of the PATH directories
$(pwd):$PATH, or its backtick-based equivalent, is extremely inefficient compared to $PWD/$PATH; like any other command substitution, it forks a subshell.
@CharlesDuffy I doubt that he types faster than pwd executes. Still, it achieves the same and is more efficient, so I editted the answer.
@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).
And you need to have Python installed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.