I want to run:

python3 myfile.py > myfile.html

However No such file or directory always pops up even though I can see the file on my desktop?

  • 1
    You mußt give the absolute Path to python3. This way it looks in the current directory. pwd will show where you are. Example ` python3 $HOME/python-skripte/Hallo-world.py` This is an absolut path. $HOME is a Variable that point to your home directory. pwd /home/alex/python-skripte python3 Hallo-world.py Now I use the relative path because I'm in the folder that contains the file. ls -l insgesamt 20 -rw-r--r-- 1 alex alex 62 Mai 3 2011 Hallo-world.py – user192526 Jan 27 '17 at 11:16

When you type

python3 myfile.py >myfile.html

in the terminal, it is assumed that the file myfile.py is already available in the current directory, and that myfile.html will be created in that same directory.

When you open up a new terminal window, the current directory will by default be your home directory, also known as ~ or $HOME.

However, you say that you can "see the file on your desktop", which likely means that the file is in fact in a desktop directory somewhere beneath your home directory, i.e. the file is not directly available in the home directory.

You then have a few possible alternatives.

  1. Change directory in the terminal to where the Python script is actually located. If the desktop directory is ~/Desktop, then

    cd ~/Desktop

    will take you there. You may then run the python3 command as above. The myfile.html file will be created in the Desktop directory.

  2. Move the file into your home directory. Provided that the file is located in the ~/Desktop directory, you may

    mv ~/Desktop/myfile.py ~/

    which will move the file. You may then proceed with the python3 command as above. The myfile.html will be created in the home directory.

  3. Run the Python script with an complete path from the home directory:

    python3 ~/Desktop/myfile.py >myfile.html

    The myfile.html file will be created in the home directory.


I'm guessing you are not in the correct directory. Try this:

cd ~/Desktop
python3 myfile.py > myfile.html

Check the current directory you are with:

$ pwd

If you are not on $HOME/Desktop/, navigate to it (using cd ~/Desktop/). After, run this command:

$ ls 

This command will list all the files on the currently dir, check if you find myfile.py. If you prefer you can filter your search using grep, like this:

$ ls | grep 'myfile.py'

After you confirm that in the currently dir you are has a file named myfile.py, you will be able to run:

python3 myfile.py > myfile.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.