Permissionerror errno 13 permission denied python linux

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container build error — PermissionError: [Errno 13] Permission denied: ‘/usr/lib/python3.8 #10613

Container build error — PermissionError: [Errno 13] Permission denied: ‘/usr/lib/python3.8 #10613

Comments

Expected Behavior

Following the steps listed at https://dev.qgroundcontrol.com/master/en/getting_started/container.html to build QGC.
Expect that the build container got built successfully.

Current Behavior

There is an error while building the container.
PermissionError: [Errno 13] Permission denied: ‘/usr/lib/python3.8/pycache/future.cpython-38.pyc.139795054894752′

Читайте также:  Сайт начинающего верстальщика

Steps to Reproduce:

  1. Install docker using steps here: https://docs.docker.com/engine/install/ubuntu/
  2. Using commit «Update PX4 Firmware metadata Fri Dec 30 06:49:42 UTC 2022»
  3. docker build —file ./deploy/docker/Dockerfile-build-linux -t qgc-linux-docker .

System Information

image

  • Operating System: [Ubuntu 22.04.1 LTS]
  • QGC sourcecode:

Detailed Description

Have reinstalled docker and remove all images but to no avail.

Log Files and Screenshots

image

The text was updated successfully, but these errors were encountered:

Hello,
I have a similar error.

Selecting previously unselected package libpython3.7-minimal:amd64. Preparing to unpack . /4-libpython3.7-minimal_3.7.3-2+deb10u4_amd64.deb . Unpacking libpython3.7-minimal:amd64 (3.7.3-2+deb10u4) . Preparing to unpack . /5-libexpat1_2.2.6-2+deb10u6_amd64.deb . Unpacking libexpat1:amd64 (2.2.6-2+deb10u6) over (2.2.6-2+deb10u4) . Selecting previously unselected package python3.7-minimal. Preparing to unpack . /6-python3.7-minimal_3.7.3-2+deb10u4_amd64.deb . Unpacking python3.7-minimal (3.7.3-2+deb10u4) . Setting up libpython3.7-minimal:amd64 (3.7.3-2+deb10u4) . Setting up libexpat1:amd64 (2.2.6-2+deb10u6) . Setting up python3.7-minimal (3.7.3-2+deb10u4) . Traceback (most recent call last): File "/usr/lib/python3.7/py_compile.py", line 212, in sys.exit(main()) File "/usr/lib/python3.7/py_compile.py", line 204, in main compile(filename, doraise=True) File "/usr/lib/python3.7/py_compile.py", line 169, in compile importlib._bootstrap_external._write_atomic(cfile, bytecode, mode) File "", line 112, in _write_atomic PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.7/__pycache__/__future__.cpython-37.pyc.139921434723696' dpkg: error processing package python3.7-minimal (--configure): installed python3.7-minimal package post-installation script subprocess returned error exit status 1 Errors were encountered while processing: python3.7-minimal E: Sub-process /usr/bin/dpkg returned an error code (1) The command '/bin/sh -c apt-get update -y && apt-get install -y python3-dev gcc build-essential pipenv locales locales-all vim && rm -rf /var/www/html && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100 
ARG VERSION_PYTHON="3.10.6-slim-buster" FROM python:$ ENV PYTHONUTNBUFFERED 1 LABEL verion="1.0.0" \ team="devops" RUN apt-get update -y && apt-get install -y python3-dev gcc \ build-essential pipenv locales locales-all vim \ && rm -rf /var/lib/apt/lists/* RUN useradd -s /bin/bash check WORKDIR /app COPY Pipfile* ./ RUN set -ex && pipenv install --deploy --system COPY . /app RUN chown check /app/check_free_space.py USER check CMD [ "/usr/local/bin/python3", "-u", "/app/check_free_space.py" ] 

Источник

Python PermissionError: [Errno 13] Permission denied

If we provide a folder path instead of a file path while reading file or if Python does not have the required permission to perform file operations(open, read, write), you will encounter PermissionError: [Errno 13] Permission denied error

In this article, we will look at what PermissionError: [Errno 13] Permission denied error means and how to resolve this error with examples.

What is PermissionError: [Errno 13] Permission denied error?

We get this error mainly while performing file operations such as read, write, rename files etc.

  1. Insufficient privileges on the file or for Python
  2. Passing a folder instead of file
  3. File is already open by other process

How to Fix PermissionError: [Errno 13] Permission denied error?

Let us try to reproduce the “errno 13 permission denied” with the above scenarios and see how to fix them with examples.

Case 1: Insufficient privileges on the file or for Python

Let’s say you have a local CSV file, and it has sensitive information which needs to be protected. You can modify the file permission and ensure that it will be readable only by you.

Now let’s create a Python program to read the file and print its content.

# Program to read the entire file (absolute path) using read() function file = open("python.txt", "r") content = file.read() print(content) file.close()
Traceback (most recent call last): File "C:/Projects/Tryouts/python.txt", line 2, in file = open("python.txt", "r") PermissionError: [Errno 13] Permission denied: 'python.txt'

When we run the code, we have got PermissionError: [Errno 13] Permission denied error because the root user creates the file. We are not executing the script in an elevated mode(admin/root).

In windows, we can fix this error by opening the command prompt in administrator mode and executing the Python script to fix the error. The same fix even applies if you are getting “permissionerror winerror 5 access is denied” error

In the case of Linux the issue we can use the sudo command to run the script as a root user.

Alternatively, you can also check the file permission by running the following command.

ls -la # output -rw-rw-rw- 1 root srinivas 46 Jan 29 03:42 python.txt

In the above example, the root user owns the file, and we don’t run Python as a root user, so Python cannot read the file.

We can fix the issue by changing the permission either to a particular user or everyone. Let’s make the file readable and executable by everyone by executing the following command.

We can also give permission to specific users instead of making it readable to everyone. We can do this by running the following command.

chown srinivas:admin python.txt 

When we run our code back after setting the right permissions, you will get the following output.

Dear User, Welcome to Python Tutorial Have a great learning . Cheers

Case 2: Providing the file path

In the below example, we have given a folder path instead of a valid file path, and the Python interpreter will raise errno 13 permission denied error.

# Program to read the entire file (absolute path) using read() function file = open("C:\\Projects\\Python\\Docs", "r") content = file.read() print(content) file.close()
Traceback (most recent call last): File "c:\Personal\IJS\Code\program.py", line 2, in file = open("C:\\Projects\\Python\\Docs", "r") PermissionError: [Errno 13] Permission denied: 'C:\\Projects\\Python\\Docs'

We can fix the error by providing the valid file path, and in case we accept the file path dynamically, we can change our code to ensure if the given file path is a valid file and then process it.

# Program to read the entire file (absolute path) using read() function file = open("C:\\Projects\\Python\\Docs\python.txt", "r") content = file.read() print(content) file.close()
Dear User, Welcome to Python Tutorial Have a great learning . Cheers

Case 3: Ensure file is Closed

While performing file operations in Python, we forget to close the file, and it remains in open mode.

Next time, when we access the file, we will get permission denied error as it’s already in use by the other process, and we did not close the file.

We can fix this error by ensuring by closing a file after performing an i/o operation on the file. You can read the following articles to find out how to read files in Python and how to write files in Python.

Conclusion

In Python, If we provide a folder path instead of a file path while reading a file or if the Python does not have the required permission to perform file operations(open, read, write), you will encounter PermissionError: [Errno 13] Permission denied error.

We can solve this error by Providing the right permissions to the file using chown or chmod commands and also ensuring Python is running in the elevated mode permission .

Источник

Оцените статью