33

I attempt to run a python program and the following pops up in command prompt:

"Unable to initialize device PRN"

I should also mention that the program runs fine.

1

11 Answers 11

70

I had this same problem when I accidentally typed "print program.py" instead of "python program.py". The error message comes from the Windows command-line program named print. Those who suggested restarting the command prompt probably committed the same typo without noticing, and corrected it in their new command prompt.

2
  • 2
    I Imagine the majority of people have a python script and have accidentally tried executing it without feeding it to the python command and hence it's been treaded as a batch command and this error has occurred on meeting the first 'print' function/statement. Apr 2, 2021 at 9:08
  • Damn it... made the same mistake ... even after 10+ years of writing Python ;) May 30 at 10:57
4

I know this is an old question, but I experienced this issue in VS Code after installing the latest version of Python and the Python extension.

To fix it, I just needed to add the Python installation path to my PATH environment variable.

  • On Windows 10, go to Settings and search for Environment
  • Click on Edit environment variables for your account
  • Select Path and click the Edit button
  • If the path to your Python.exe is not listed, click the New button
  • Enter the path to your Python.exe application and click the OK button
    • The path for me was %LocalAppData%\Programs\Python\Python37-32\
  • Restart VS Code and try to run your python script again
4

I encountered this in VS Code. I had run some lines of code (using Shift + Enter), which starts a Python interpreter in a terminal, and then I called quit() at the terminal, to exit Python. If you try to run some more lines of code, it doesn't start another Python interpreter, it just runs those lines in the terminal, which of course doesn't work and causes error messages like the one in the question.

Two easy solutions are either to start a new Python interpreter in the terminal (by entering python), or killing the active terminal instance (the dustbin icon), before running more lines of code.

1
  • 2
    The same problem as yours, ran few python lines using Shift+Enter, then exited the python interpreter using exit() and next time when I ran python lines using Shift+Enter, it gave the error message: " Unable to initialize device PRN". I used your solution and it worked perfectly. But I did not know how to kill terminal using "the dustbin icon", instead I typed "exit" in the terminal, and my problem is gone. Thank You.
    – jay_phate
    May 22, 2021 at 5:08
3

First of all install latest version of Python from it's official website (i.e. python.org/download) after that if you try to run it through command prompt instead of writing python3 just write python. After that >> it will appear then start writing your actual code. Make sure you re-run the command prompt window.Sample Image

1
  • This has nothing to do with python. In the window above, the user has used the 'print' command on the command line, not within python. Apr 2, 2021 at 9:06
2

In my case restarting (close / open new) the console or the Command Prompt window works

0
2

I had the same problem by accidentally sending the word "print" to the command line from my programming which DOS interprets as the DOS command to print to the printer.

1

Try changing name of the program; that worked for me. Don't forget: use fresh cmd when you start executing.

1

I am using VS code and I just noticed this issue today. Google a little and I comment out all the print function still not working. I exit the vs code and launch it again and it works just perfectly.

0
1

I had the same problem when using Netstat print route in order to view the routing table. It gave the error: 'Unable to initialize device PRN' . It disappeared when I used the equivalent netstat -r (and it did print out the routing table)

0

To fix this, add python.exe to system varible in your windows On Windows 10, go to Settings and search for Environment Click on Edit environment variables for your account Select Path and click the Edit button If the path to your Python.exe is not listed, click the New button Enter the path to your Python.exe application and click the OK button and restart the application

0

Please try to enter python in terminal and then execute the same command . In terminal type "Python" then run the command print("Hi"). It will work.

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