I am using python fabric in my project mainly for deployment to the remote server. Inside the fabfile, i have written a function named deploy() for pulling the code to the github. When i execute the command "fab deploy", it results in an error like this:
error: cannot open .git/FETCH_HEAD: Permission denied
Please help me in resolving this issue. Any help is much appreciated. Thanks in advance
Check permissions and ownership of .git directory and files in it
ls -al .git | grep FETCH_HEAD
There should be something like -rw-r--r-- at the beginning of output.
If not fix it by setting them by:
sudo chmod -R 0755 .git
Related
I recently upgraded to Mac Big Sur and have noticed my Python 3.8 cron jobs have stopped working. Under my own account in a bash shell, I can run this without issues ...
davea$ cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python3 manage.py check_duplicates
In my crontab, I had this set up, which used to work before the upgrade ...
*/5 * * * * /bin/bash -l -c 'cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python manage.py check_duplicates >> /Users/davea/logs/record2.txt 2>&1'
However, after the upgrade, I'm noticing my command is never run and I see this issue in my log file
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'manage.py': [Errno 1] Operation not permitted
These are the permissions/groups on my "manage.py" file ...
davea$ ls -al manage.py
-rwxrwxr-x 1 davea staff 866 Apr 15 2019 manage.py
What else do I need to do to get my cron job to run again?
Turns out with the new Mac OS there is an extra level of permissions that need to be enabled. In System Preferences, under Security and Privacy, I clicked the Privacy tab, and then added "cron" to the "Full disk Access" list
then the cron jobs ran without the permissions error.
I think in this case, python3 is considered as "any user" and with the -rwxrwxr permission it only have right to read the file, try to run chmod 775 manage.py in your folder to add permission to manage.py to be executed by "any user" (rigths should be set to -rwxrwxr), hope it can help.
EDIT: technically, read permission should be enough for python to run a file, but I can't see another reason why this error would appear, and I would be interested if you find one
This looks like a SIP or other mac-specific access permissions error, especially since it was right after an upgrade. Could be: https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/
I've also had lots of problems working with venvs with cron, could be related to this: https://stackoverflow.com/a/7031758/13113166
It's also weird that the error comes from /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 when i think it should come from your venv if it's activated correctly.
I tried to install selenium on Ubuntu using this syntax:
conda install -c conda-forge selenium
It fails with this error
Collecting package metadata (current_repodata.json): failed
NotWritableError: The current user does not have write permissions to a required path.
path: /home/<redacted>/.conda/pkgs/urls.txt
uid: 1000
gid: 1000
If you feel that permissions on this path are set incorrectly, you can manually
change them by executing
$ sudo chown 1000:1000 /home/<redacted>/.conda/pkgs/urls.txt
In general, it's not advisable to use 'sudo conda'.
I tried to execute this command to check the permission of the file:
ls -l /home/<redacted>/.conda/pkgs/urls.txt
It turns out that the file doesn't exist:
ls: cannot access '/home/<redacted>/.conda/pkgs/urls.txt': No such file or directory
In fact, I checked the folder /home/<redacted>/.conda/, but the only file exists is environments.txt
-rw-r--r-- 1 root root 24 Agu 26 09:44 environments.txt
I don't know how to fix this. Should I just create an empty file?
Given that your environments.txt is owned by root, your .conda folder is probably also owned by root. Since you're not currently root, you can't modify the .conda folder or anything in it.
I'm guessing that you installed anaconda to your home area using the root user or sudo; good news, since you apparently have sudo privileges you can just give yourself recursive ownership of the .conda folder using chown: chown -R <redacted>:<redacted> .conda.
I've recently been tearing my hear out over this trivial problem, nothing I found online has helped me so far. I am using virtualenv, my project structure :
myproj\
..bin
..tasks.py
..celery_app.py
..projapi
where importFolder is an API folder with a bunch of files in it. proj.py is my script that does all the work and contains imports like
sys.path.append("/abspath/to/projapi")
import projapi
I can source bin/activate and enter my virtualenv just fine, but when I go back a directory and run the celery worker:
celery -A myproj worker --app=myproj.celery_app:app -l info
I'll get an import error for every folder in the myproj directory such as importerror for 'projapi'. It's as if the virtualenv is looking for all files in only the /bin dir (where as my proj is in myproj dir)
How can I fix this? I've tried appending all sorts of system and python paths, both in activate and in my tasks.py, but to no avail.
Probably you are using system wide celery.
Try to install it with pip within virtual env and repeat execution, that would fix your issue.
Also verify that each folder where you .py located contains __init__.py file.
Have you tried changing the celery call itself?
celery -A celery_app worker -E -l INFO
I am currently reading a book called "Test-Driven Development with Python" In chapter1, I have to use
git rm -r --cached superlists/__pycache__
to remove all the .pyc files, I got the error the same in the title. I have searched many similar problems in this forum, I still cannot figure it out how to solve it. Hope someone could help me. Many Thanks
I got the same error while doing executing the same command:
Solution 1:
One of the stackoverflow answers mentions his usual buildout have the have .pyc in the .gitignore file - link to the answer
I did that and then did the "$ git add ." command. It worked and the __pycache__ files were not added.
$echo "*.pyc" >> .gitignore
Solution 2:
I cleaned the staging area for the files to be commited
and then executed the same command. It worked
$git reset
$git rm -r --chached superlists/__pycache__
screenshot for Solution 2
Hope it helps!
Your error, Error fatal: pathspec did not match any files, means that the pathspec you specified (superlists/__pycache__) doesn't match any files that are being tracked by git.
In the previous steps had you added the __pycache__ files to git?
Are there any __pycache__ files in the superlists directory? Have you run the superlists code? Perhaps you have your python configured to not output .pyc cache files?
What is the output of ls -a superlists and ls -a superlists/__pycache__?
I am trying to upload image through admin page, but it keeps saying:
[Errno 13] Permission denied: '/path/to/my/site/media/userfolder/2014/05/26'
the folders userfolder/2014/05/26 are created dynamically while uploading.
In Traceback, i found that the error is occuring during this command:
In /usr/lib64/python2.6/os.py Line 157. while calling
mkdir(name, mode)
meaning, it cannot create any folder as it doesnot have the permission to do this
I have OpenSuse as OS in Server. In httpd.conf, i have this:
<Directory /path/to/my/site/media>
Order allow,deny
Allow from all
</Directory>
Do I have to chmod or chown something?
You need to change the directory permission so that web server process can change the directory.
To change ownership of the directory, use chown:
chown -R user-id:group-id /path/to/the/directory
To see which user own the web server process (change httpd accordingly):
ps aux | grep httpd | grep -v grep
OR
ps -efl | grep httpd | grep -v grep
This may also happen if you have a slash before the folder name:
path = '/folder1/folder2'
OSError: [Errno 13] Permission denied: '/folder1'
comes up with an error but this one works fine:
path = 'folder1/folder2'
Probably you are facing problem when a download request is made by the maybe_download function call in base.py file.
There is a conflict in the permissions of the temporary files and I myself couldn't work out a way to change the permissions, but was able to work around the problem.
Do the following...
Download the four .gz files of the MNIST data set from the link ( http://yann.lecun.com/exdb/mnist/ )
Then make a folder names MNIST_data (or your choice in your working directory/ site packages folder in the tensorflow\examples folder).
Directly copy paste the files into the folder.
Copy the address of the folder (it probably will be
( C:\Python\Python35\Lib\site-packages\tensorflow\examples\tutorials\mnist\MNIST_data ))
Change the "\" to "/" as "\" is used for escape characters, to access the folder locations.
Lastly, if you are following the tutorials, your call function would be ( mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ) ;
change the "MNIST_data/" parameter to your folder location. As in my case would be ( mnist = input_data.read_data_sets("C:/Python/Python35/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data", one_hot=True) )
Then it's all done.
Hope it works for you.
Another option is to ensure the file is not open anywhere else on your machine.
supplementing #falsetru's answer : run id in the terminal to get your user_id and group_id
Go the directory/partition where you are facing the challenge.
Open terminal, type id then press enter.
This will show you your user_id and group_id
then type
chown -R user-id:group-id .
Replace user-id and group-id
. at the end indicates current partition / repository
// chown -R 1001:1001 . (that was my case)
Simply try:
sudo cp /source /destination
Just close the file in case it is opened in the background. The error disappears by itself
The solution that worked out for me here when I was using python 3 os package for performing operations on a directory where I didn't have sufficient permissions and access to got resolved by running the python file with sudo (root) i.e.:
sudo python python_file_name.py
Any other utility that you might also plan on using to chmod or chown that directory would also only work when you run it with sudo.
# file_name.py
base_path = "./parent_dir/child_dir/"
user = os.stat(base_path).st_uid # for getting details of the current user owner of the dir
group = os.stat(base_path).st_gid # for getting details of the current group owner of the dir
print("Present owner and group of the specified path")
print("Owner:", user)
print("Group:", group)
os.chown(base_path, user, group) # change directory permissions
print("\nOwner id of the file:", os.stat(base_path).st_uid)
print("Group id of the file:", os.stat(base_path).st_gid)
os.mkdir(base_path+file_name,mode=0o666)
run the above file with sudo.
sudo python file_name.py
Hope this answer works out for you.
Forever indebted to stackoverflow and the dev community. All hail the devs.