- Permission denied error while writing to a file in Python
- 9 Answers 9
- Permission denied error when trying to install pip in Mac OS X Lion
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged python macos osx-lion pip or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- [Errno 13] Permission denied on Mac OS X #3823
- Comments
- volkanunsal commented Jul 2, 2019 •
- Issue description
- Permission problems when creating a dir with os.makedirs in Python
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged python python-2.7 or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Run script on mac prompt «Permission denied»
- 7 Answers 7
Permission denied error while writing to a file in Python
I want to create a file and write some integer data to it in python. For example, I have a variable abc = 3 and I am trying to write it to a file (which doesn’t exist and I assume python will create it on its own):
First, will python create a newfile.dat on its own? Secondly, it’s giving me this error:
What’s wrong here?
9 Answers 9
Please close the file if its still open on your computer, then try running the python code. I hope it works
This also happens when you attempt to create a file with the same name as a directory:
I’ve had the same issue using the cmd (windows command line) like this
Where inside the python file something like this
The error was that when you don’t use a full path, python would use your current directory, and because the default directory on cmd is
that won’t work, as it seems to be write-protected and needs permission & confirmation form an administrator
Instead, you should use full paths, for example:
Permission denied simply means the system is not having permission to write the file to that folder. Give permissions to the folder using «sudo chmod 777 » from terminal and try to run it. It worked for me.
I write python script with IDLE3.8(python 3.8.0) I have solved this question: if the path is shelve.open(‘C:\\database.dat’) it will be PermissionError: [Errno 13] Permission denied: ‘C:\\database.dat.dat’ . But when I test to set the path as shelve.open(‘E:\\database.dat’) That is OK. Then I test all the drive(such as C,D,F. ) on my computer,Only when the Path set in Disk
will get the permission denied error. So I think this is a protect path in windows to avoid python script to change or read files in system Disk(Disk C)
To answer your first question: yes, if the file is not there Python will create it.
Secondly, the user (yourself) running the python script doesn’t have write privileges to create a file in the directory.
Источник
Permission denied error when trying to install pip in Mac OS X Lion
I’m trying to install pip on a Mac (OS X Lion). It doesn’t seem to work. I use sudo and prompted for password.
The error log mentioned at the bottom.
4 Answers 4
You are running the curl (download) command under sudo , but the python process itself is running without elevated privileges.
Run it like this instead:
Alternatively, use the sudo command on the python part of the pipe instead:
I met the same question. And I fix it by the following steps:
In terminal use this command : sudo python get-pip.py
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python
Might be because you don’t have permission to python folder. Please try this, it worked for me.
- $ sudo chown -R $USER /Library/Python/2.7
Not the answer you’re looking for? Browse other questions tagged python macos osx-lion pip or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
[Errno 13] Permission denied on Mac OS X #3823
Comments
volkanunsal commented Jul 2, 2019 •
Issue description
I’m using Miniconda (Python 3.7.3) with Pipenv. But I don’t think it’s related to Miniconda, it happens with system Python as well.
Here is what is happening. I installed pipenv using Homebrew.
Then I tried to install the package black , and this is what I saw:
Since I read in the documentation that pipenv CLI API is compatible with pip , I tried passing in —user flag
But I got the same error. Then I tried changing the target directory of pip to Miniconda’s site-packages folder from pip.conf and the error went away, but the packages were not installed into pipenv virtual environment, so this wasn’t a solution.
I tried using sudo -H with pipenv install and that worked as well, but it also changed the permissions of all files in the virtualenv, making it near impossible to do anything without sudo .
Then I cleared the contents of /Users/newuser/.pydistutils.cfg since that seemed to be what the error message was complaining about. And that seemed to work. But I had not changed this before. The only thing that it had was something like prefix=» .
Please run $ pipenv —support , and paste the results here. Don’t put backticks ( ` ) around it! The output already contains Markdown formatting.
Pipenv version: ‘2018.11.26’
Pipenv location: ‘/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv’
Python location: ‘/usr/local/Cellar/pipenv/2018.11.26_2/libexec/bin/python3.7’
Python installations found:
- 3.7.3 : /miniconda3/bin/python3
- 3.7.3 : /usr/local/bin/python3
- 3.7.3 : /usr/local/bin/python3.7m
- 3.7.0 : /miniconda3/bin/pythonw
- 2.7.16 : /usr/local/bin/python
- 2.7.16 : /usr/local/bin/pythonw
- 2.7.10 : /usr/bin/python
- 2.7.10 : /usr/bin/pythonw
- 2.7.10 : /usr/bin/python2.7
PEP 508 Information:
System environment variables:
- PATH
- MANPATH
- rvm_use_flag
- rvm_bin_path
- TERM_PROGRAM
- NVM_CD_FLAGS
- rvm_ruby_alias
- rvm_quiet_flag
- GEM_HOME
- rvm_gemstone_url
- TERM
- SHELL
- rvm_docs_type
- IRBRC
- TMPDIR
- GOBIN
- Apple_PubSub_Socket_Render
- TERM_PROGRAM_VERSION
- MY_RUBY_HOME
- TERM_SESSION_ID
- GIT_EDITOR
- NVM_DIR
- USER
- rvm_user_flag
- rvm_gemstone_package_file
- COMMAND_MODE
- rvm_path
- SSH_AUTH_SOCK
- __CF_USER_TEXT_ENCODING
- rvm_proxy
- rvm_ruby_file
- AUTOFEATURE
- PAGER
- rvm_sticky_flag
- LSCOLORS
- rvm_silent_flag
- rvm_prefix
- rvm_ruby_make
- _
- NVM_NODEJS_ORG_MIRROR
- PWD
- JAVA_HOME
- HOMEBREW_GITHUB_API_TOKEN
- EDITOR
- rvm_system_flag
- rvm_sdk
- LANG
- ITERM_PROFILE
- XPC_FLAGS
- XPC_SERVICE_NAME
- rvm_version
- rvm_script_name
- rvm_pretty_print_flag
- SHLVL
- HOME
- COLORFGBG
- rvm_ruby_mode
- DIGITALOCEAN_TOKEN
- rvm_ruby_string
- rvm_archflags
- ITERM_SESSION_ID
- LESS
- LOGNAME
- rvm_alias_expanded
- GEM_PATH
- LC_CTYPE
- NVM_BIN
- GOPATH
- NVM_IOJS_ORG_MIRROR
- rvmsudo_secure_path
- rvm_nightly_flag
- rvm_file_name
- R_HOME
- rvm_ruby_make_install
- rvm_niceness
- rvm_delete_flag
- DISPLAY
- SSH_FINGERPRINT
- rvm_ruby_bits
- rvm_bin_flag
- rvm_only_path_flag
- RUBY_VERSION
- SECURITYSESSIONID
- COLORTERM
- PIP_DISABLE_PIP_VERSION_CHECK
- PYTHONDONTWRITEBYTECODE
- PIP_SHIMS_BASE_MODULE
- PIP_PYTHON_PATH
- PYTHONFINDER_IGNORE_UNSUPPORTED
Pipenv–specific environment variables:
Debug–specific environment variables:
- PATH : /usr/local/Cellar/pipenv/2018.11.26_2/libexec/tools:/Users/newuser/google-cloud-sdk/bin:/Users/newuser/.local/bin:/usr/local/opt/llvm@4/bin:/usr/local/opt/curl/bin:/Users/newuser/Library/Go/bin:/Users/newuser/.nvm/versions/node/v8.11.2/bin:/Users/newuser/.rvm/gems/ruby-2.3.7@licp/bin:/Users/newuser/.rvm/gems/ruby-2.3.7@global/bin:/Users/newuser/.rvm/rubies/ruby-2.3.7/bin:/Users/newuser/.rvm/bin:/Users/newuser/Dropbox/Tools/z:/Users/newuser/bin:/usr/local/Cellar/postgresql/10.4/bin:/miniconda3/bin:/Users/newuser/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/usr/local/m-cli:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/Users/newuser/.rvm/bin
- SHELL : /bin/zsh
- EDITOR : /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
- LANG : en_US.UTF-8
- PWD : /Users/newuser/forks/licp/vendor/citiesense
Contents of Pipfile (‘/Users/newuser/forks/licp/vendor/citiesense/Pipfile’):
Contents of Pipfile.lock (‘/Users/newuser/forks/licp/vendor/citiesense/Pipfile.lock’):
The text was updated successfully, but these errors were encountered:
Источник
Permission problems when creating a dir with os.makedirs in Python
I’m simply trying to handle an uploaded file and write it in a working dir which name is the system timestamp. The problem is that I want to create that directory with full permission (777) but I can’t! Using the following piece of code the created directory with 755 permissions.
4 Answers 4
According to the official python documentation the mode argument of the os.makedirs function may be ignored on some systems, and on systems where it is not ignored the current umask value is masked out.
Either way, you can force the mode to 0o777 (0777 threw up a syntax error) using the os.chmod function.
You are running into problems because os.makedir() honors the umask of current process (see the docs, here). If you want to ignore the umask, you’ll have to do something like the following:
In your case, you’ll want to desired_permission to be 0777 (octal, not string). Most other users would probably want 0755 or 0770.
For Unix systems (when the mode is not ignored) the provided mode is first masked with umask of current user. You could also fix the umask of the user that runs this code. Then you will not have to call os.chmod() method. Please note, that if you don’t fix umask and create more than one directory with os.makedirs method, you will have to identify created folders and apply os.chmod on them.
For me I created the following function:
The other anwsers did not worked for me (with python 2.7).
I had to add os.umask(0) before, to remove the mask for the current user. And I had to change the mode from 0777 to 0o777 :
Not the answer you’re looking for? Browse other questions tagged python python-2.7 or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
Run script on mac prompt «Permission denied»
I’m new to mac with not familiar on terminal command, i put the dvtcolorconvert.rb file on root directory of my volume, this ruby script can converting xcode 3 themes into xcode 4 themes format, which is xxxxxxxx.dvtcolortheme format.
Then run the script /dvtcolorconvert.rb
/Themes/ObsidianCode.xccolortheme on terminal, but it’s always prompt «Permission denied«.
what’s wrong with this? Anybody can help me solve this problem? Thanks.
7 Answers 7
Did you give yourself the rights to execute the script?
The following command as super user will do this for you:
sudo chmod 755 ‘filename’
For details you should read the man page of chmod.
Please read the whole answer before attempting to run with sudo
Try running sudo /dvtcolorconvert.rb
The sudo command executes the commands which follow it with ‘superuser’ or ‘root’ privileges. This should allow you to execute almost anything from the command line. That said, DON’T DO THIS! If you are running a script on your computer and don’t need it to access core components of your operating system (I’m guessing you’re not since you are invoking the script on something inside your home directory (
/)), then it should be running from your home directory, ie:
/ or a sub directory and execute from there. You should never have permission issues there and there wont be a risk of it accessing or modifying anything critical to your OS.
If you are still having problems you can check the permissions on the file by running ls -l while in the same directory as the ruby script. You will get something like this:
You will notice that the readme.txt file says -rw-r—r— on the left. This shows the permissions for that file. The 9 characters from the right can be split into groups of 3 characters of ‘rwx’ (read, write, execute). If I want to add execute rights to this file I would execute chmod 755 readme.txt and that permissions portion would become rwxr-xr-x . I can now execute this file if I want to by running ./readme.txt (./ tells the bash to look in the current directory for the intended command rather that search the $PATH variable).
schluchc alludes to looking at the man page for chmod, do this by running man chmod . This is the best way to get documentation on a given command, man
Источник