I have several bash scripts that I define in the crontab planner to run. This is what the script looks like:
#!/bin/bash
source /home/administrator/anaconda3/bin/activate
python /share/****/VK_RU_YAR.py
conda deactivate
As you can see, anaconda is installed under the administrator. But I myself work under a different user, but I have sudo rights. How can I apply them correctly in the script so that everything works.
Error:
Could not find conda environment:
You can list all discoverable environments with `conda info --envs`.
Traceback (most recent call last):
File "/share/RosAtom-V/Work/VK_RU_YAR.py", line 17, in <module>
from check_size import checking
File "/share/RosAtom-V/Work/check_size.py", line 6, in <module>
set_log(log_conf)
File "/share/RosAtom-V/Work/clogs.py", line 4, in set_log
fileh = logging.FileHandler(file, 'a')
File "/home/administrator/anaconda3/lib/python3.8/logging/__init__.py", line 1143, in __init__
StreamHandler.__init__(self, self._open())
File "/home/administrator/anaconda3/lib/python3.8/logging/__init__.py", line 1172, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/share/RosAtom-V/Logs/log_script.txt'
Separate execution of the python script does not cause errors.
Related
I'm quite new to Scrapy and found this error baffling me big time. I work on a Windows machine and use a Ubuntu subsystem (WSL) to do all my development work. I have created a virtual environment and trying to start learning Scrapy, however, whenever I am in the virtual environment and try to create a new project, the following error shows up and the files cannot be created successfully.
OS: Windows 10
Environment: Windows 10 - WSL Ubuntu 20.04.1
Python: Python 3.8.5
Recreate issue:
python3 -m venv /Directory/
source /Directory/bin/activate
(venv) pip install scrapy
(venv) scrapy startproject /directory/
Error Message:
Traceback (most recent call last):
File "/mnt/c/Users/.../bin/scrapy", line 10, in <module>
sys.exit(execute())
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/cmdline.py", line 145, in
execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/cmdline.py", line 100, in
_run_print_help
func(*a, **kw)
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/cmdline.py", line 153, in
_run_command
cmd.run(args, opts)
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/commands/startproject.py", line 110, in run
self._copytree(self.templates_dir, abspath(project_dir))
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/commands/startproject.py", line 83, in _copytree
self._copytree(srcname, dstname)
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/commands/startproject.py", line 83, in _copytree
self._copytree(srcname, dstname)
File "/mnt/c/Users/.../lib/python3.8/site-packages/scrapy/commands/startproject.py", line 88, in _copytree
copystat(src, dst)
File "/usr/lib/python3.8/shutil.py", line 376, in copystat
_copyxattr(src, dst, follow_symlinks=follow)
File "/usr/lib/python3.8/shutil.py", line 326, in _copyxattr
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
PermissionError: [Errno 13] Permission denied: '/mnt/c/Users/.../module/spiders'
The strange thing is that when I am not using a virtual environment, it works just fine. Is there any way I could fix this?
Thank you so much.
Instead of
python3 -m venv /Directory/
Try
python3 -m venv Directory
The former one puts your virtual environment as directory under / instead of in the current directory.
(Please don't call your virtual environment Directory ;) )
I'm on Mac OS 10.9 and running Python 3.5.2
I tried updating conda
conda update conda
but it gave me this error
Traceback (most recent call last):
File "/Users/cd/anaconda3/bin/conda", line 6, in <module>
sys.exit(main())
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/cli/main.py", line 139, in main
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/cli/main.py", line 146, in args_func
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/cli/main_update.py", line 64, in execute
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/cli/install.py", line 424, in install
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/plan.py", line 539, in execute_actions
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/instructions.py", line 149, in execute_instructions
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/instructions.py", line 92, in LINK_CMD
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/instructions.py", line 88, in link
File "/Users/cd/anaconda3/lib/python3.5/site-packages/conda/install.py", line 634, in link
File "/Users/cd/anaconda3/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/Users/cd/anaconda3/etc/fish/conf.d’
I searched around and thought the problem was that I needed to chown the folder with my user (which is 'cd' in my case):
sudo chown -R cd anaconda3
Then I tried conda update conda, but now it gives a different error:
zsh: /Users/cd/anaconda3/bin/conda: bad interpreter: /opt/anaconda1anaconda2anaconda3/bin/python3: no such file or directory
I tried putting chownback to root:
sudo chown -R root anaconda3
but when I tried conda update conda it gave me the same "bad interpreter" error.
where conda gives /Users/cd/anaconda3/bin/conda
I don't know if the problem was the chowncommand or not, but please let me know if you need any more details!
Your shebang line in /Users/USER/anaconda/bin/conda is broken:
#!/opt/anaconda1anaconda2anaconda3/bin/python
just switch it back to point to the link of your install of Anaconda:
#!/Users/USER/anaconda/bin/python
I installed newrelic on my OS(Ubuntu 14.04) in python3.4, then generate newrelic.ini via license key, after that I run this command:
sudo newrelic-admin run-program python backend/__main__.py
but after that i've get this error :
Traceback (most recent call last):
File "/usr/local/bin/newrelic-admin", line 9, in <module>
load_entry_point('newrelic==2.50.0.39', 'console_scripts', 'newrelic-admin')()
File "/usr/local/lib/python3.4/dist-packages/newrelic-2.50.0.39/newrelic/admin/__init__.py", line 128, in main
callback(sys.argv[2:])
File "/usr/local/lib/python3.4/dist-packages/newrelic-2.50.0.39/newrelic/admin/run_program.py", line 96, in run_program
os.execl(program_exe_path, *args)
File "/usr/lib/python3.4/os.py", line 489, in execl
execv(file, args)
PermissionError: [Errno 13] Permission denied
i've run that with sudo but it throws permission denied anyway! why this happens and how can i prevent this? any help would be appreciated.
You have to change the permission of your bootstarp file in your project like this:
sudo chmod 755 YOUR_FILE.py
Trying to create a virtualenv using the command:
mkvirtualenv -p /usr/local/lib/python3.2 splinter
Gives me the response:
Running virtualenv with interpreter /usr/local/lib/python3.2
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.2/dist-packages/virtualenv.py", line 784, in main
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
File "/usr/lib/python3.2/subprocess.py", line 745, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.2/subprocess.py", line 1361, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 13] Permission denied
How oh how can I start a virtualenv using python3.2?
You need to supply the path to the path to the Python interpreter with -p, not the lib directory.
Because you're passing that directory, virtualenv is trying to execute it, and therefore you get Permission denied. So use the path to the python executable in the bin directory instead (use which python3.2 to find out if you don't know the location).
This should work, assuming your Python 3.2 interpreter can be found at /usr/local/bin/python3.2:
mkvirtualenv -p /usr/local/bin/python3.2 splinter
I tried to create a new virtualenv directory with sudo virtualenv curdir -p /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 and it threw the following error:
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.6.4', 'console_scripts', 'virtualenv')()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/virtualenv.py", line 785, in main
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 741, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/subprocess.py", line 1356, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 13] Permission denied
I understand that I was not allowed to do that, but why? python 2.7 is located there and I want to use it. Is there any way to use it in my virtualenv?
I hope that this isn't too basic of a question. I am still pretty new to Unix command line.
You have to point to the python executable, which you are not doing here. Its located at /Library/Frameworks/Python.framework/Versions/2.7/bin/python. Run this
sudo virtualenv curdir -p /Library/Frameworks/Python.framework/Versions/2.7/bin/python