sudo virtualenv -p gives PermissionError: [Errno 13] Permission denied? - python

When I try to run
sudo virtualenv -p /Library/Frameworks/Python.framework/Versions/7.3/Resources/Python.app/Contents/MacOS
It shows the following error:
Running virtualenv with interpreter
/Library/Frameworks/Python.framework/Versions/7.3/Resources/Python.app/Contents/MacOS
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.8.2', 'console_scripts', 'virtualenv')()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/virtualenv.py", line 897, in main
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 1416, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
I tried removing my pip.log file as this answer advised me to, but the problem persists. Any solutions?
Edit:
I should explain that I'm trying to create a virtualenv located at the <path name> because I want to install a package with pip for that version of Python.

Related

FileNotFoundError: [Errno 2] No such file or directory: 'python': 'python' while running a python script

While trying to run a python script on EC2 (running ubuntu), I'm getting this error:
Traceback (most recent call last):
File "128d.py", line 9, in <module>
"--pca_params", "./vggish_pca_params.npz"])
File "/usr/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'python': 'python'
All the dependencies are installed. I've tested the script on my home machine (Windows 10), and it works just fine. I can see that something is wrong with python installed on the EC2 machine, probably. But I didn't manage to find an answer on the web.
I've fixed the problem.
Turns out, I had my python installed in a folder that was named python3. So, when the suprocess.py file tried to find python in path, it wasn't there.
I've renamed python3 in /usr/bin/ to python and the problem is fixed.
P.S. However, keep in mind, that it might raise some other issues. When I tried to aws s3 cp, it was looking for python3 instead. Maybe adding another copy of that folder as python3 would help.

FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

i have installed the tasseract using
pip install pytesseract
whenever i tried to run this piece of code
from PIL import Image
import pytesseract
im = Image.open('hasan1.jpg')
print (pytesseract.image_to_string(im))
I got these errors.
Traceback (most recent call last):
File "ocr.py", line 34, in <module>
text = pytesseract.image_to_string(Image.open(filename))
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
I believe PyTesseract requires you to have the tesseract library installed on your system - PyTesseract is trying to run the command-line interface but it can't find it presumably because you have only installed the python bindings.
If you are on an Ubuntu/Debian-based system, you can try:
sudo apt-get install tesseract-ocr
You can check the Tesseract installation docs for more info: https://github.com/tesseract-ocr/tesseract/wiki

creating a virtualenv gives a permission denied

I'm trying to create a virtualenv, but I'm getting a Permission denied error. I'm using the following code
python2.7 -m virtualenv -p `which python2.7` test
Which gives this error message:
--edit--
I get a permission denied error
Traceback (most recent call last):
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 287, in clobber
ensure_dir(dest) # common for the 'include' path
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 152, in makedirs
makedirs(head, mode)
File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 159, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/lib/python2.7'
and a final error the operation failed
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 2328, in <module>
main()
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 945, in create_environment
download=download,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/marco/developm...m/test/bin/python2.7 - setuptools pip wheel failed with error code 2
To debug the error in os.py, I've added a print statement, it looks like the script tries to make the directories /lib/python2.7 and /lib/python2.7/site-packages. I don't understand why virtualenv tries to create these directories there and not in my current directory.
I've installed virtualenv without sudo, so I don't expect it to create directories in a path that is owned by root.
In the end only the python executable is copied to the 'test' directory, but not setuptools, pip and wheels.
Is there a way to avoid virtualenv from accessing root owned directories?
--update--
using python3 with venv works fine, the problem is with virtualenv specifically.
Executing virtualenv from my home directory give no error.
Looks like you're trying to create the virtualenv test within /lib/python2.7/site-packages, which, by all rights, you shouldn't have write access to.
Try running cd ~ first, to create the venv in your home directory.
I had the same mysterious error; it turns out I had forgotten a setting in my $HOME/.pip/pip.conf that changed the prefix.

can't use tesseract so how to install tesseract on virtualenv?

I created a virtualenv via command venv. Then I installed tesseract via command brew install tesseract. But I can use it only on actual env, when I use it on virtualenv, an error No such file or directory: 'tesseract' is thrown:
BlockquoteTraceback (most recent call last):
File "/Users/abc/PycharmProjects/spider/demo2.py", line 5, in <module>
vcode = pytesseract.image_to_string(image)
File "/Users/abc/env1/lib/python3.5/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
config=config)
File "/Users/abc/env1/lib/python3.5/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

jsoncpp : error while building the documentation

I'm trying to build jsoncpp's documentation (https://github.com/open-source-parsers/jsoncpp) in Ubuntu 14.10. As said in the github's README.md, I run the doxybuild.py script but I get the following error :
$> cd jsoncpp/
$> python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
Deleting directory: dist/doxygen
Running: /home/jeremy/Projets/Perso/CmdSeries/libs/jsoncpp/doc/doxyfile
Traceback (most recent call last):
File "doxybuild.py", line 169, in <module>
main()
File "doxybuild.py", line 166, in main
build_doc( options )
File "doxybuild.py", line 116, in build_doc
ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent )
File "doxybuild.py", line 67, in run_doxygen
process = subprocess.Popen( cmd )
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
$> sudo python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
Deleting directory: dist/doxygen
Running: /home/jeremy/Projets/Perso/CmdSeries/libs/jsoncpp/doc/doxyfile
Traceback (most recent call last):
File "doxybuild.py", line 169, in <module>
main()
File "doxybuild.py", line 166, in main
build_doc( options )
File "doxybuild.py", line 116, in build_doc
ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent )
File "doxybuild.py", line 67, in run_doxygen
process = subprocess.Popen( cmd )
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Does anyone have an idea ?
Already tried :
chmod u+x doxybuild.py
sudo chmod 775 /usr/lib/python2.7/subprocess.py
sudo chown $USER /usr/lib/python2.7/subprocess.py
But nothing resolved my problem.
Ok, problem solved :
$> cd jsoncpp/doc
$> cat readme.txt
The documentation is generated using doxygen (http://www.doxygen.org).
$> sudo apt-get install doxygen
...
OK
$> python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
...
ok
Just install doxygen and building the documentation will work.

Categories