Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX and sudo install requirements #34

Closed
glitchassassin opened this issue May 2, 2017 · 7 comments
Closed

OSX and sudo install requirements #34

glitchassassin opened this issue May 2, 2017 · 7 comments

Comments

@glitchassassin
Copy link
Contributor

When trying to install opencv-python on OS X (python3 installed via Homebrew), installing as an unprivileged user failed with the following message:

Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
File "/usr/local/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
File "/usr/local/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 377, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/usr/local/LICENSE-3RD-PARTY.txt'

After installing with sudo -H pip3 install opencv-python, the package worked.

Can the sudo requirement be eliminated by not writing the license to /usr/local/?

@skvark
Copy link
Member

skvark commented May 2, 2017

You can try pip install --user opencv-python or use virtualenvs. And you are correct, sudo should not be used to install packages with pip.

However, the root of this issue lies in MacOS or in how some of its package managers handle Python installations. I'm not too famialiar with all the MacOS weirdness, but the data_files parameter in setup.py uses relative paths so distutils behaves just like documented. If I move the licenses to a subfolder in this package, the issue stays the same. Even if there are no data_files, the problem would still most likely persist.

I have no access to a Mac currently, but this should be pretty easy to test with a dummy package. Moving the licenses to package_data in setup.py could also help if the issue is related only to the data_files.

@impact27
Copy link

@impact27
Copy link

In would think that the licenses should be package_data. from installing-package-data:

These files are often data that’s closely related to the package’s implementation

data_files is used for a general purpose. It can be install pretty much wherever installing-additional-files:

If directory is a relative path, it is interpreted relative to the installation prefix

The installation prefix here is /usr/local, which is probably not where the license should be saved.
I will admit I do not fully understand what the target directory is:

You can specify the data_files options as a simple sequence of files without specifying a target directory, but this is not recommended, and the install command will print a warning in this case. To install data files directly in the target directory, an empty string should be given as the directory.

But this issue can probably be solve by using package_data instead of data_files.

@skvark
Copy link
Member

skvark commented Jul 17, 2017

Yes, I agree that moving the files into package_data might help. Feel free to open pull request.

Note that the Travis builds are currently broken (I don't know yet why) but I'm going try to fix the issue asap since OpenCV 3.3.0 release is getting closer.

@impact27
Copy link

I am not sure where to include them. Should the files be installed in the cv2 folder?
A bit more insight: pypa/pip#2874 (comment)

@skvark
Copy link
Member

skvark commented Jul 17, 2017

I'm not sure either, but I would like to keep the license files in the root of this project so that they can be found easily. I would have used MANIFEST.in to collect the additional data files but it's not supported in binary wheels. Some options:

Option 1

Add

[metadata]
license_file = <license filename>

to setup.cfg. This requires that all the licenses are moved into a single file. See: https://bitbucket.org/pypa/wheel/issues/138/include-more-than-one-license-file-or

Option 2

Copy the license files during build to cv2 folder and include them there with package_data. This is probably better because the licenses can be kept separated.

Please comment if you have any better ideas. For some reason Python's packaging tools make these simple looking things unbelievably complex.

@glitchassassin
Copy link
Contributor Author

Submitted a pull request for package_data.

skvark pushed a commit that referenced this issue Jul 22, 2017
* Moved license files to package_data

* Moved license files

* Copying licenses to cv2 in Travis step

* Added license copy to Windows build script
@skvark skvark closed this as completed Jul 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants