Cannot remove virtualenv directory from PC - python

I've tried rm -rf venvpc and I get the error message:
rm: cannot unlink `venvpc/Scripts/python.exe': Permission denied
rm: cannot remove directory `venvpc/Scripts': Directory not empty
rm: cannot remove directory `venvpc': Directory not empty
I removed the virtualenv name 'venvpc' from PyCharm in case there was a link there.
I tried removing via Windows Explorer and it says the folder or a file in it is open in another program.
What can I try next?

You need to do it as root user , so use sudo (on linux) :
sudo rm -rf venvpc
and if you are in windows run runas /noprofile /user:Administrator cmd to command as admin.

Related

PHP to access run shell script

I have this PHP script that basically runs a shell script. The shell script takes a python file name main.py and gives output and stores it in a file after the output file gets to move to a different folder.
My PHP code:
<?php
if ($_GET['run']) {
# This code will run if ?run=true is set.
exec("/home/ubuntu/python/script.sh");
}
?>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
Click Me!
Myscript code is this:
#!/bin/bash
/usr/bin/python3 /home/ubuntu/python/main.py > /home/ubuntu/python/output/mainOut
mv /home/ubuntu/python/main.py /home/ubuntu/python/outputMain
My Script is working fine when I run it using command but with PHP it is giving me permission denied error. I tried changing the user name or adding sudo to the script but it is not working. any suggestion will help.
this is my Error log:
mv: cannot move '/home/ubuntu/python/main.py' to '/home/ubuntu/python/outputMain/main.py': Permission denied
Quick and dirty workaround : sudo chmod 777 /home/ubuntu/python -R
If you want to solve it proper, here's my thinking:
First check apache/nginx's running user & group
Then check it's permission on such file/folder (that't not neccessary but it shows the problem more specific)
Finally change the nginx-user's group like usermod -aG GROUP USER then sudo chmod 775 DIR -R (or you can make the permission more preciselly)
The diffrence of 777 and 775 is : 777 makes any user on your server could edit that file, when '775' only allowed owner and group members edit it.
If im not wrong you need to perform sudo chmod 755 or 777 on the .sh, and thats all.

How can i create a virtual environment on Pydroid3

I had tried it, but this was the result, please check below.
/storage/emulated/0 $ cd venv3
/storage/emulated/0/venv3 $ virtualenv .
PermissionError: [Errno 1] Operation not permitted: '/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/bin/python3.8' -> '/storage/emulated/0/venv3/bin/python'
/storage/emulated/0/venv3 $```
If you are using termux or something like that and your phone isn't root, go to your $HOME directory via one of these commands: cd or cd $HOME .
Then you can run virtualenv . .
You can't run some special things in your phone storage (if your phone isn't root), for example , you can't run a bash script in /storage/emulated/0/... .

Run bash script from pydroid inbuilt terminal. Install miniconda on Android. Access sdcard from UserLAnd

chd.sh
#! /bin/bash
cd django/hellodjango
exec bash
python manage.py runserver
chd.py
# a=`python chd.py`;cd $a
import os
new_dir = "django/hellodjango"
os.chdir(new_dir)
are the two ways I have tried.
Also, on terminal I have tried,
. chd.sh
./chd.sh
. ./chd.sh
I have also tried to assign to variable and then run on terminal but no success.
Spent over 4 hours trying multiple methods given on stackoverflow.com but no success yet.
The only thing that has worked yet is,
alias mycd='cd django/hellodjango'
But I will have to copy paste it everytime.
alias myrun = `cd django/hellodjango && python manage.py runserver`
And,
alias myrun = `cd django/hellodjango; python manage.py runserver`
doesn't work.
This is just a sample, there are so many django commands that I have to use repeatedly. Appreciate if you have read all this way.
If you know the link where this is discussed, please attach the link, as I was not able to find after hours of search.
Edit:
/storage/emulated/0 $
This is what the prompt appears like.
/storage/emulated/0/django/hellodjango
This is the path.
/storage/emulated/0 $ cd django/hellodjango
/storage/emulated/0/django/hellodjango $ python manage.py
runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
July 25, 2020 - 19:08:42
Django version 3.0.7, using settings 'hellodjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Individually works fine.
Edit:
/storage/emulated/0 $ chmod u+x chd.sh /storage/emulated/0 $ chmod u+x
rn.sh /storage/emulated/0 $ ./chd.sh ./chd.sh: cd: line 2: can't cd t:
No such file or directory /storage/emulated/0 $ chmod u+x chd.py
/storage/emulated/0 $ a=python chd.py;cd $a
~/data/ru.iiec.pydroid3/app_HOME $
Edit:
/data/user/0/tech.ula/files/support/dbclient: Caution, skipping
hostkey check for localhost
subham#localhost's password:
subham#localhost:~$ ls
subham#localhost:~$ cd
subham#localhost:~$ pwd
/home/subham
subham#localhost:~$ pkg install miniconda
-bash: pkg: command not found
subham#localhost:~$ apt install miniconda
Reading package lists... Done Building dependency tree
Reading state information... Done
E: Unable to locate package miniconda
subham#localhost:~$
subham#localhost:~$ cd ..
subham#localhost:/home$ cd ..
subham#localhost:/$ ls
bin dev host-rootfs mnt root srv
sys var boot etc lib opt run storage tmp data home
media proc sbin support usr
subham#localhost:/$ cd ..
subham#localhost:/$ cd sys
subham#localhost:/sys$ ls
ls: cannot open
directory '.': Permission denied
subham#localhost:/sys$ cd..
-bash: cd..: command not found
subham#localhost:/sys$ cd ..
subham#localhost:/$ cd storage
subham#localhost:/storage$ ls internal
subham#localhost:/storage$ cd internal
subham#localhost:/storage/internal$ ls
subham#localhost:/storage/internal$ ls -l total 0
subham#localhost:/storage/internal$ cd 0
-bash: cd: 0: No such file or directory subham#localhost:/storage/internal$
subham#localhost:/$ chmod -R 777 /host-rootfs
chmod: changing permissions of '/host-rootfs': Read-only file system
chmod: cannot read directory '/host-rootfs': Permission denied
subham#localhost:/$
https://github.com/CypherpunkArmory/UserLAnd/issues/46

Error PYTHON_EGG_CACHE while uploading django

I am trying to upload my django project live and I am continuously getting this error:
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/opt/bitnami/.tmp/simplejson-2.0.9-py2.7-linux-x86_64.egg-tmp/simplejson/tmpuYcIYB.$extract'
The Python egg cache directory is currently set to:
/opt/bitnami/.tmp
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
It is a permissions / ownership problem. You can solve it using these commands:
sudo su bitnami
sudo find /opt/bitnami/apps/django/ -type d -exec chmod 755 {} \;
sudo find /opt/bitnami/apps/django/ -type f -exec chmod 644 {} \;
sudo chown -R bitnami:daemon /opt/bitnami/apps/django/
You must also deploy your projects to the following path: /opt/bitnami/apps/django/django_projects/YOURPROJECT

Fabric receives permission denied while execute rm -rf

When I run the fabric.py to deploy my site ton Ubuntu.
I met the error:
[192.168.15.143] run: rm -rf /home/user/project/weather_station/
[192.168.15.143] out: rm: cannot remove '/home/user/project/weather_station/logs/gunicorn.log': Permission denied
[192.168.15.143] out:
Fatal error: run() received nonzero return code 1 while executing!
Requested: rm -rf /home/user/project/weather_station/
Executed: /bin/bash -l -c "rm -rf /home/user/project/weather_station/"
Aborting.
Disconnecting from 192.168.15.143... done.
My think is that the error is about the permission denied.
I referenced this
So I changed run('rm -rf {}'.format(PROJECT_DIR))into sudo('rm -rf {}'.format(PROJECT_DIR))
but still error.Is there any approach?
Is the /home/user/project/weather_station/logs/gunicorn.log file in use by an active process? If gunicorn is running and using this file as a log file, then "Permission denied." is exactly what should happen. If this is the case, then you need to re-consider what you're trying to do, as you shouldn't be deleting a file that's being used.
In the case of a log file, the obvious solution would be to configure gunicorn to use a different location, like /home/user/logs/weather_station, so that it's outside of the path that you're trying to delete.
That point aside, if you stop the gunicorn process before executing this rm command, then your command should run successfully.
The broad issue, however, is that (I think) you're trying to delete a log file that's in use. You either need to configure gunicorn to use a different location for its log file, or else you need to end gunicorn before you attempt to delete it.
I finally use sudo chmod 777 /home/user/project/weather_station/logs/gunicorn.log
Then it does work.

Categories