pdfminer.six: /usr/bin/env: ‘python\r’: No such file or directory
pdf2txt.py fails to run with:
/usr/bin/env: ‘python\r’: No such file or directory
This appears to be due to a DOS carriage return in the shebang line. Running dos2unix pdf2txt.py appears to fix the issue.
Test environment:
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Release: 16.04 Codename: xenial
pdfminer.six (20160614) - from PyPi via pip
Running in a virtualenv
$ virtualenv --version 15.0.1
$ python --version Python 3.5.1+
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 34 (13 by maintainers)
Problem still persists as I just installed it using pip on
Ubuntu 16.04.3 LTSand had to manually fixpdf2txt.pyto get it to work.I ran
sed $'s/\r//' -i $(which pdf2txt.py)to fix the problem.Fixed problem with
vim
which pdf2txt.py:set ff=unix :wq
To clarify, this was how I patched the installed script:
vim `which pdf2txt.py`:set ff=unix:wqThis is just a reformatted version of @tiru1930’s solution
Some good news: I was able to install directly from the current version using
I’ve confirmed this as tests are now passing for textract (hallelujah!). When a new version of
pdfminer.sixis released, I believe you can close this out @goulu.Thanks for managing
pdfminerand helping to merge many great ideas into the package!In the latest version 20170720 the problem still persist if the package is installed from pypi. If you install it directly from github there is no problem, because the file in git is ok.
@goulu on what OS did you prepare the package for PyPi?
The problem is that in Unix like OSes (Linux/BSD/MacOS etc.) in the first line of executable text file there should not be present a
\rcharacter, because this will mess the shell trying to figure out which interpreter to start in order to execute the file.As we see in the code everything is ok but there is some problem in the process of creating the package which is uploaded to PyPi.
Both
pdf2txt.pyanddumppdf.pyhave this issue. Fixed it by :set ff=unixin vimpdfminer.six using pip on Ubuntu zesty
thanks for the quick reply @bittner! That’s the output of
pip show pdfminer.six, which seems to be the lastest version if I’m not mistaken.I changed the shebang line This works on ubuntu for python3 from: /usr/bin/env: ‘python\r’ to : /usr/bin/env: ‘python3\r’
But this still didn’t solve the issue. I had to convert the file from dos format to unix format.
sudo apt-get install dos2unixand then find the file by
whereis pdf2txt.pyand then convert the file to unix formatsudo dos2unix pathto(pdf2txt.py)This is quite a nasty bug. easy fix is
dos2unix pdf2txt.pyShouldn’t have to if this bug gets fixed.Strange. According to the commit log the
\rissue should have been fixed for that version.@goulu How do you
sdist uploadnew releases? Withpython setup.pyor manually? Are you on a Windows machine?@gedankenstuecke How did you install the module, and which version is it?
(Run
pip show pdfminer.six, maybe?)Just a heads up, I’ve run
dos2unixover all the following files in PR #58*.py*.md*.rst*.yml.gitignoreMakefileMANIFEST.in… and the result is that only
.travis.ymlwas still affected.Oh. Sorry. I got confused. It is working for me in Ubuntu. I don’t know if there is still a problem with this PR in other operating systems.
I only tried this with OSX, but my previous points should apply equally to any Unix environment with python2 and python3 installed side by side.
If you want to migrate to using entry points, the basic idea is that you refactor each of the tools into a function in a module, and then map the name of the tool to that function. So setup.py would contain something like:
In this configuration, pdf2txt.py is simply part of the pdfminer package. the
pdf2txtexecutable is generated on install and callspdfminer.pdf2txt.main().I’m sure there are other ways to do it, but I like this method because it plays well with pip developer mode:
pip3 install -e .. In developer mode changes to the source code are immediately visible to the installed scripts.This is a problem with installing pdfminer.six in a virtualenv