#[Errno 2] No such file or directory - python

So, here what I am doing
from the below link:
https://django-microsoft-auth.readthedocs.io/en/latest/installation.html#from-sources
I am trying to follow all the steps mention in the blog for the installation of django_microsoft_auth.
Step-1 i.e. "pip install django_microsoft_auth" # is working
Step-2 i.e. "git clone git://github.com/AngellusMortis/django_microsoft_auth" # is also working
Step-3 i.e. "python setup.py install" # is giving me the below error.
C:\Users\vtinkhed\AppData\Local\Programs\Python\Python37\python.exe:
can't open file 'setup.py': [Errno 2] No such file or directory
I don't know how to help. Could anybody help me out here?
Thanks in advance

You need to start setup.py from the folder where it is located.
Use cd to get to that folder, then run python setup.py install

I had the same Issue. My problem was that my script had a space in in. ' hello.py' instead of 'hello.py'. After renaming it worked well.

Related

Pytessaract image_to_pdf_or_hocr function not working in AWS lambda

I am using this repository to deploy tesseract as a lambda layer: https://github.com/bweigel/aws-lambda-tesseract-layer
The deployment works well and other functions that pytesseract has like: image_to_string, image_to_data also works well without any hiccups.
But, when I try to use image_to_pdf_or_hocr like this:
pdf = pytesseract.image_to_pdf_or_hocr(f'/tmp/{file_name}/{page.number}.png', extension='pdf')
it does not work and throws error like:
Traceback (most recent call last):
File "/var/task/helpers/ocr_helper.py", line 36, in save_searchable_pdf
f'/tmp/{file_name}/{page.number}.png', extension='pdf')
File "/var/task/pytesseract/pytesseract.py", line 432, in image_to_pdf_or_hocr
return run_and_get_output(*args)
File "/var/task/pytesseract/pytesseract.py", line 289, in run_and_get_output
with open(filename, 'rb') as output_file:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tess_6_hu78b0.pdf'
It says that the file tess_6_hu78b0.pdf does not exist. What does this mean? I have no file with tess_6_hu78b0 name to begin with.
The path that I am passing to image_to_pdf_or_hocr function is 100% correct and an image is present there. I have confirmed and the same thing works on my local.
I have tried:
I found somewhere that I needed to install libtesseract-dev too. Hence, I modified my dockerfile as:
FROM lambci/lambda:build-python3.6
RUN sudo apt install tesseract-ocr
RUN sudo apt install libtesseract-dev
but unfortunately this too did not work.
After 18 hours of hard work, I was finally able to figure it out.
It turns out that https://github.com/bweigel/aws-lambda-tesseract-layer is not bundled with all the necessary files for pytesseract.image_to_pdf_or_hocr() to run.
So what I did was, I build leptonica and tesseract from source and generated
configs folder
tessconfigs folder and
pdf.tiff file
These required files are available here:
https://github.com/prameshbajra/tessdata
Inside https://github.com/bweigel/aws-lambda-tesseract-layer, under ready-to-use folder there is a directory named amazonlinux-1, and inside it, there is a folder named tesseract/share/tessdata. All you need to do is paste in the above listed files under this directory.
Just download this repo and replace the tessdata folder.
Note: This tessdata is build with tesseract 4.1.1
I hope this helps future readers.
Happy coding.
Thank Benjamin Genz (#bweigel) for publishing this repo. You made our lives easier.
Adding this config argument fixed it for me, inspired by this solution :)
pytesseract.image_to_pdf_or_hocr("Image.png", extension="pdf", config = " -c tessedit_create_pdf=1")

How to use pipreqs to create requirements.txt file

I am trying to use the pipreqs package to generate a requirements.txt file. Following the documentation's examples I have been unable to make it work.
It seems simple enough, the documentation tells me to use this command in the terminal:
$ pipreqs /home/project/location
In my case, this is the location of my project:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal
And I get this error message:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/requirements.txt'
The error message is correct, there is no requirements.txt file in that directory. I am trying to use pipreqs to create the requirements.txt file.
Reading the documentation, pipreqs is supposed to scan a python file for import statements and build the requirements.txt document based on that. So I tried this as well, with the file I want pipreqs to scan:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal/1FigrFunctions.py
and I received this error, which is pretty much the same as above:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/1FigrFunctions.py/requirements.txt'
I am sure the solution is obvious. What am I doing wrong?
I answered my own question. I think the errors were due to there being a bunch of files in the directory I was trying to run pipreqs on. To solve this problem, I created a new empty directory called "test" and put the file I wanted to generate requirements.txt for in that directory. So there is only one file in my new "test" directory. Then I ran the command as follows:
$ pipreqs /Users/ep9k/Desktop/test
and it worked. Really simple...
I discovered how to solve this error using below steps-
If you want to specify full path for your python file, use this -
pipreqs --encoding utf-8 "C:\Users\username\Downloads\Bl_container\training\fold\"
Also, the python file should be alone in the folder.
If you are currently in your python file directory, use this -
pipreqs --encoding utf-8 "./"
Using encoding to get rid of the map error.
Make sure that you are not connected to any VPN or you may get HTTPConnection error.
Have you tried:
$ pipreqs --encoding utf-8 "/Users/ep9k/Desktop/UVA/Big/Deal" --force
I've managed to create requirement.txt for multiple .py files in one dir.
Use Pigar instead, i have a lot of problems with pipreqs
https://github.com/Damnever/pigar
pip install pigar

Setting up CPLEX with Python on Mac

I'm trying to install cplex on Python on my Mac but I'm really stuck.
The setup.py file is in the following path:
/Users/mac/Applications/IBM/ILOG/CPLEX_Studio127/cplex/python/2.7/x86-64_osx
I am using canopy for running Python.
I entered the following code in Terminal of Mac and the result was as follows:
macs-mbp:~ mac$ python setup.py install
/Users/mac/Library/Enthought/Canopy_64bit/User/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory
macs-mbp:~ mac$
I then decided to use (option --home) but the result was also terrible:
macs-mbp:~ mac$ python setup.py install --home /Users/mac/Applications/IBM/ILOG/CPLEX_Studio127/cplex
/Users/mac/Library/Enthought/Canopy_64bit/User/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory
macs-mbp:~ mac$
I tried using cd too but that didn't yield an improvement.
Any help would be appreciated for installing cplex on Python on Mac!
This looks like it might be similar to this SO question.
What happens if you do the following:
cd /Users/mac/Applications/IBM/ILOG/CPLEX_Studio127/cplex/python/2.7/x86-64_osx
python setup.py install
Also, you have to make sure that the "python" above points to the python you want (canopy vs the system python).

python: can't open an existing file even if the path has already been clearly added

I am using python 2.7.11 and I have downloaded setuptools-2.2 for its included setup.py file. Then I did a python setup.py install (This command is successful), and I added the path for this setup.py file to ~/.bash_profile.
export PATH=/opt/python2711/lib/python2.7/site-packages/:$PATH
export PATH=/path-to-setuptools/setuptools-2.2/:$PATH
However, when I tried to install another software (./pybombs install uhd), my computer kept complaining:
Build failed. Re-trying with reduced makewidth and higher verbosity.
python: can't open file 'setup.py': [Errno 2] No such file or directory
I actually tried to add the path of that egg file as well, but it couldn't help either. I don't know much about this setup.py file. Could somebody point out how to fix this compiling error?
Thanks in advance!
add your path in ~/.profile
export PATH=$PATH:/path/to/dir
~/.profile: executed by the command interpreter for login shells.
how ever the path variable is in
/etc/environment : file open and add the path here you should log in as root

"Cannot access setup.py: No such file or directory" - can't run any .py files?

This problem started while I was installing pyswip and needed to run a setup.py file. Using the command "python setup.py", I'm greeted with the following message: "python: can't open file 'setup.py': [Errno 2] No such file or directory."
I know this question's been asked a lot before, so I've tried everything in previous answers. Including #!/usr/bin/env python or #!/usr/bin/env python-3.3.0 at the very top of the script and then trying "chmod +x setup.py"
gives the following: "chmod: cannot access setup.py': No such file or directory".
Trying to run other .py files from the terminal gives the same result.
Running the file in the Python Shell from IDLE doesn't do anything.
Running the "ls -d */" command shows that the Python-3.3.0/ directory, where the .py files in question are, is definitely there.
Am I missing something really obvious? (If it helps, I have Elementary OS 0.2.)
When you run python setup.py that requires the setup.py file to be in the current directory.
You can control the current directory with the cd command.
So:
cd /home/acacia/Python-3.3.0/PySwip/pyswip-0.2.3
python setup.py install
I have no knowledge about Elementary OS but you could try to use the full path of the setup.py.
python /home/acacia/Python-3.3.0/PySwip/pyswip-0.2.3/setup.py install
[EDIT] Can't answer comments, so I just added the install parameter in my answer
You need to go into the directory that you are going to "setup". For example, if you are installing numpy, and you have git-cloned it, then it probably is located at ~/numpy. So first cd into ~/numpy, and the type the commend like "python setup.py build" there.

Categories

Resources