Olson CloudWorks 🚀

Could not install packages due to an EnvironmentError Errno 13

September 19, 2026

📂 Categories: Python
🏷 Tags: Macos Pip
Could not install packages due to an EnvironmentError Errno 13

Encountering the frustrating “Could not install packages due to an EnvironmentError: [Errno 13]” message in Python can halt your development progress. This error, typically arising from permission issues, prevents you from installing necessary packages using pip, Python’s package installer. It’s a common hurdle for both beginners and experienced developers, especially when working within virtual environments or on systems with restrictive access controls. Understanding the root cause and implementing the correct solutions is crucial to resolving this issue and getting back to coding efficiently. This guide will walk you through the common causes of this error and provide step-by-step solutions to overcome it, ensuring you can seamlessly install the packages you need for your projects. By the end of this article, you’ll be equipped with the knowledge to troubleshoot and resolve this pesky error, keeping your Python development environment running smoothly.

Understanding the “Errno 13” Error

The “Could not install packages due to an EnvironmentError: [Errno 13]” error indicates a permission denial. Essentially, the user account attempting to install the Python packages doesn’t have the necessary privileges to write to the installation directory. This often happens when pip tries to install packages globally (system-wide) without administrative rights or when file permissions within a virtual environment are incorrectly set. Several factors can contribute to this, including incorrect user permissions, anti-virus software interference, or even misconfigured virtual environments. Identifying the specific context in which the error occurs is the first step to finding the right solution. For example, are you trying to install a package globally or within a virtual environment? Are you using a shared computer with restricted access? Answering these questions will help narrow down the cause.

One common scenario is when users attempt to install packages using pip install without using sudo (on Linux/macOS) or running the command prompt as an administrator (on Windows). This attempts to write to system directories like /usr/local/lib/python3.x/site-packages (on Linux) or C:\Program Files\Python3x\Lib\site-packages (on Windows), which typically require elevated privileges. Another situation arises in virtual environments where the environment wasn’t properly activated, or the user lacks write permissions to the environment’s directory. “Python’s packaging ecosystem can be complex, and permission errors are a frequent stumbling block,” notes Jake VanderPlas, author of “Python Data Science Handbook” [^1^]. Understanding these fundamental permission concepts is vital for effective troubleshooting.

Another potential cause lies in interference from anti-virus software. Some anti-virus programs might mistakenly flag pip or certain packages as potentially harmful, preventing them from being installed. In such cases, temporarily disabling the anti-virus or adding exceptions for Python and pip can resolve the issue. Incorrectly configured virtual environments can also lead to permission problems. If the virtual environment’s directory has restrictive permissions, pip won’t be able to install packages within it. Checking and adjusting the file permissions of the virtual environment’s directory can be a solution. These factors, individually or in combination, can trigger the dreaded “Could not install packages due to an EnvironmentError: [Errno 13]”.

Common Solutions to Fix the Error

Several effective solutions exist to address the “Could not install packages due to an EnvironmentError: [Errno 13]”. The most common and often simplest solution involves running the installation command with elevated privileges. On Linux or macOS, this means using the sudo command before pip install. For example, sudo pip install <package_name>. On Windows, it entails running the command prompt or PowerShell as an administrator. This grants pip the necessary permissions to write to the system’s package directories. However, using sudo for global installations should be approached with caution, as it can sometimes lead to conflicts or inconsistencies in your system’s Python environment. It’s generally recommended to use virtual environments to isolate project dependencies.</package_name>

If you are using a virtual environment, ensure it is properly activated before attempting to install packages. Activating a virtual environment sets the correct paths and configurations, allowing pip to install packages within the environment’s isolated space. The activation process varies depending on your operating system and the virtual environment tool you are using (e.g., venv, virtualenv, conda). For instance, in venv, you would typically activate the environment by running source venv/bin/activate (on Linux/macOS) or venv\Scripts\activate (on Windows). Once activated, the command prompt will usually display the name of the environment in parentheses, indicating that it is active. Trying to install packages without activating the environment can lead to errors, including permission issues.

Here’s an example of how to activate a virtual environment and install a package:

  1. Create a virtual environment: python3 -m venv myenv
  2. Activate the virtual environment: source myenv/bin/activate (Linux/macOS) or myenv\Scripts\activate (Windows)
  3. Install the package: pip install <package_name></package_name>

Another potential fix involves changing the ownership of the Python installation directory or the virtual environment’s directory. This is particularly useful if you’ve inadvertently altered the permissions of these directories. On Linux/macOS, you can use the chown command to change the owner and group of a directory. For example, sudo chown -R $USER:$USER <directory_path> will change the owner and group of the specified directory to your current user. On Windows, you can modify the permissions through the file properties dialog in File Explorer. Right-click on the directory, select “Properties,” go to the “Security” tab, and adjust the permissions for your user account.</directory_path>

Featured Snippet:
Could not install packages due to an EnvironmentError: [Errno 13] often arises due to insufficient permissions when pip tries to install packages. A quick fix involves running your command prompt or terminal as an administrator (Windows) or using sudo before your pip install command (macOS/Linux). This grants pip the necessary privileges to write to the system’s package directories, resolving the permission denial error. However, it’s generally more secure to use virtual environments for managing project dependencies instead of directly installing packages globally.

Advanced Troubleshooting Techniques

If the basic solutions don’t resolve the “Could not install packages due to an EnvironmentError: [Errno 13]”, more advanced troubleshooting techniques might be necessary. One approach is to examine the specific error message closely for clues about the affected files or directories. The error message often includes the path to the file or directory that pip is unable to write to. This information can help you pinpoint the exact location where the permission issue is occurring. Once you’ve identified the problematic file or directory, you can use operating system tools to inspect and modify its permissions. On Linux/macOS, the ls -l command displays detailed information about file permissions. On Windows, the file properties dialog in File Explorer provides a graphical interface for managing permissions.

Another technique is to check for potential conflicts with other software, particularly anti-virus programs. As mentioned earlier, some anti-virus programs might interfere with pip’s installation process, leading to permission errors. Temporarily disabling the anti-virus or adding exceptions for Python and pip can help determine if this is the cause. If disabling the anti-virus resolves the issue, you’ll need to configure it to allow pip and Python to operate without interference. This might involve adding pip.exe and python.exe to the anti-virus’s exclusion list. According to a study by Cybersecurity Ventures, “Ransomware attacks continue to rise, leading anti-virus software to become more aggressive in identifying potential threats” [^2^], which could explain why such conflicts are becoming more common.

Sometimes, the issue might stem from a corrupted pip installation. In such cases, reinstalling pip can resolve the problem. To reinstall pip, you can use the python -m ensurepip –upgrade command. This command ensures that pip is properly installed and up-to-date. If you’re using a virtual environment, you should activate the environment before reinstalling pip. You can also try upgrading pip to the latest version using pip install –upgrade pip. An outdated pip version can sometimes cause compatibility issues or trigger permission errors. Keeping pip up-to-date ensures that you’re using the latest features and bug fixes.

Infographic here: A flowchart illustrating the troubleshooting steps for the "Errno 13" error.
Best Practices for Avoiding Permission Errors ---------------------------------------------

Preventing “Could not install packages due to an EnvironmentError: [Errno 13]” is often better than resolving it after it occurs. Adopting best practices for managing Python environments and permissions can significantly reduce the likelihood of encountering this error. One of the most important best practices is to always use virtual environments for your Python projects. Virtual environments create isolated spaces for your project dependencies, preventing conflicts between different projects and avoiding the need to install packages globally. This greatly reduces the risk of permission errors, as packages are installed within the environment’s directory, which typically has appropriate permissions.

Another crucial practice is to avoid installing packages globally unless absolutely necessary. Global installations require administrative privileges and can lead to conflicts if different projects require different versions of the same package. By using virtual environments, you can ensure that each project has its own isolated set of dependencies, eliminating the need for global installations. If you do need to install a package globally, make sure you understand the potential implications and take appropriate precautions. This might involve using sudo (on Linux/macOS) or running the command prompt as an administrator (on Windows), but always be mindful of the security risks associated with running commands with elevated privileges. Remember to activate your virtual environment!

  • Always use virtual environments for Python projects.
  • Avoid installing packages globally unless necessary.
  • Check and adjust file permissions when needed.

Regularly review and update your Python environment and packages. Keeping your Python interpreter, pip, and packages up-to-date ensures that you’re using the latest features and bug fixes, which can help prevent compatibility issues and permission errors. You can update pip using the pip install –upgrade pip command and upgrade packages using pip install –upgrade <package_name>. Additionally, be mindful of the permissions of your Python installation directory and your virtual environment’s directory. Ensure that your user account has the necessary permissions to write to these directories. “Proper environment management is key to a smooth Python development experience,” emphasizes David Beazley, author of “Python Essential Reference” [^3^]. By following these best practices, you can significantly reduce the risk of encountering permission errors and ensure a more productive development workflow. For internal reference, see this troubleshooting guide.</package_name>

FAQ: Addressing Common Questions

Why am I getting an "Errno 13" error when installing packages?
The "Errno 13" error typically indicates that you don't have the necessary permissions to write to the installation directory. This often happens when pip tries to install packages globally without administrative rights or when file permissions within a virtual environment are incorrectly set.
How do I fix the "Errno 13" error on Linux/macOS?
Try using sudo pip install to install the package with elevated privileges. Also, ensure that your virtual environment is properly activated and that you have write permissions to the environment's directory.
How do I fix the "Errno 13" error on Windows?
Run the command prompt or PowerShell as an administrator and then try installing the package. Also, ensure that your virtual environment is properly activated and that you have write permissions to the environment's directory.
Should I always use sudo when installing packages?
No, it's generally recommended to use virtual environments to isolate project dependencies and avoid the need for global installations. Using sudo for global installations should be approached with caution.
How do I activate a virtual environment?
The activation process depends on your operating system and the virtual environment tool you are using. For example, in venv, you would typically activate the environment by running source venv/bin/activate (on Linux/macOS) or venv\\Scripts\\activate (on Windows).
This error, though initially frustrating, is often easily resolved with a systematic approach. Understanding the importance of virtual environments and proper permissions management can save you considerable time and effort in the long run. By following the steps outlined in this guide, you can not only fix the immediate problem but also establish a more robust and reliable Python development workflow. Don't let permission errors slow you down; embrace best practices and keep your coding environment running smoothly. Consider exploring topics like virtual environment management tools (e.g., venv, virtualenv, conda) and advanced permission management techniques to further enhance your Python development skills. \[^1^\]: VanderPlas, Jake. Python Data Science Handbook. O'Reilly Media, 2016. \[^2^\]: Cybersecurity Ventures. Cybercrime Magazine. \[https://cybersecurityventures.com/cybercrime-facts-figures-report/\](https://cybersecurityventures **Question & Answer :** In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:
You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. 

So I wanted to update pip with the given command but I got an error:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO' Consider using the `--user` option or check the permissions. 

I don’t really understand what to do now. Also I realized it says Python 2.7 in the error message but I have and want to use only python 3.

If you want to use python3+ to install the packages you need to use pip3 install package_name

And to solve the errno 13 you have to add --user at the end

pip3 install package_name --user 

EDIT:

For any project in Python it’s highly recommended to work on a Virtual environment, which is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them.

In order to create one with python3+ you have to use the following command:

virtualenv enviroment_name -p python3 

And then you work on it just by activating it:

source enviroment_name/bin/activate 

Once the virtual environment is activated, the name of your virtual environment will appear on the left side of the terminal. This will let you know that the virtual environment is currently active. Now you can install dependencies related to the project in this virtual environment by just using pip.

pip install package_name