ERROR: Could not install packages due to an OSError: [WinError 2]

I have found a solution to fix “ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: …” this error.

If you are facing this error then no matter which package you are going to install, you will keep getting the same error again and again.

The solution to fix this is while installing any package just add --userat the end of your command. For example:

pip install package-name --user

To make it a bit simpler for example:

pip install opencv-python --user

or

pip install matplotlib --user

So whenever you face that error just add –user at the end of the installation command.

There might be other solutions to it but in my opinion, this is the best solution I have ever found. So I thought it to be worth sharing it with Python developers.

Adding --userat the end of the command will let you install the package in the user’s home directory.

Leave a Reply

Your email address will not be published. Required fields are marked *