Last updated: Apr 11, 2024
Reading time·3 min
The "Unable to initialize device PRN" error most commonly occurs when you
issue the print file_name.py
command.
To solve the error, use the python file_name.py
command instead.
Here is an example of how the error occurs.
Suppose we have the following main.py
file.
print('bobbyhadz.com') print('abc 123')
Running the following command in my terminal causes the error.
print main.py
Make sure to replace main.py
with the name of your Python script.
To solve the error, use the python main.py
command instead.
python main.py
main.py
with the name of your Python script.If you are on macOS or Linux, you might have to use the python3
command.
# on macOS and Linux python3 main.py
If you are on Windows, you might have to use the py
alias.
# Windows (py alias) py main.py
If you tried to start the Python interpreter, issue the command without supplying a filename.
python # or python3 python3 # or using the Windows py alias py
If you need to exit the Python interpreter, call the exit()
function.
exit()
If you try to run Python commands after calling exit()
, you will get the error
because you've exited the Python interpreter.
You can resolve the issue by starting a new session of the Python interpreter by
issuing the python
command.
If the error persists and your filename contains the word print
, try renaming
the file.
If you need to print a file on Windows using the command line, use the following command instead.
prn
port because the output won't be legible and you'll end up wasting paper.copy YOUR_FILE.txt lpt3 /b
Make sure to replace the YOUR_FILE.txt
placeholder with the name of the actual
file.
lpt3
is the printer port. If you get an error when using the lpt3
port, try
using lpt
.
copy YOUR_FILE.txt lpt /b
You can also try using lpt1
.
copy YOUR_FILE.txt lpt1 /b
If the error persists, make sure you have Python installed and added to your PATH environment variable.
You can download Python by visiting the official python.org website.
Once you download Python, make sure it has been added to your PATH environment variable.
You can verify that python
has been installed and added to your PATH
environment variable by issuing the python --version
command.
python --version
If you get an error when issuing the command, try to use python3
instead.
python3 --version
If the issue persists and you are on Windows, try to use the py
alias.
py --version
If you get a version number after issuing the command, then everything works as expected.
If none of the suggestions helped, try to restart your terminal session before issuing the command.
You can learn more about the related topics by checking out the following tutorials: