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

[python] library is installed in a wrong directory with --user flag #297

Open
tunz opened this issue May 1, 2017 · 5 comments
Open

[python] library is installed in a wrong directory with --user flag #297

tunz opened this issue May 1, 2017 · 5 comments

Comments

@tunz
Copy link

tunz commented May 1, 2017

version: 0.9.1

If I install keystone-engine with --user flag without virtualenv,

$ pip install --user keystone-engine

libkeystone.so is installed in a wrong directory, thus loading the keystone-engine throws an exception:

ImportError: ERROR: fail to load the dynamic library.

the libkeystone.so is installed in /home/username/.local/lib/python2.7/site-packages/usr/lib/python2.7/dist-packages/keystone/libkeystone.so, but it should be located in /home/username/.local/lib/python2.7/site-packages/keystone/libkeystone.so

it seems that capstone has the same issue.

@aquynh
Copy link
Member

aquynh commented May 1, 2017 via email

@tunz
Copy link
Author

tunz commented May 1, 2017

it's broken in pip-installed version (3.0.4) of capstone, but seems it's fixed in the master branch of capstone.

@aquynh
Copy link
Member

aquynh commented May 1, 2017

we can fix this by porting the the Python binding of Unicorn to Keystone (as they are very similar). the only related Keystone file is https://github.com/keystone-engine/keystone/blob/master/bindings/python/setup.py, and the counterpart is https://github.com/unicorn-engine/unicorn/blob/master/bindings/python/setup.py

if you can fix this, please send pull req

aquynh pushed a commit that referenced this issue Oct 24, 2017
using `data_files` dict prefixed with
`SITE_PACKAGES = os.path.join(get_python_lib(), "keystone")` is not
portable, see #235 and #297 for details. Regular setup configuration does
not work, e.g., specifying `package_data` etc, since that only affects
`sdist`.

The fix is a hack: customize `install_lib` to explicitly copy the file
into keystone install dir.
@williballenthin
Copy link

with #301 merged, i think this issue is resolved. see the below terminal session building keystone on linux/python3:

before patch:

localhost:python (master*) $ git checkout d19579217c0ac71e2d63deb389f29fb23e5a9118                                                         
Note: checking out 'd19579217c0ac71e2d63deb389f29fb23e5a9118'.                                                                           
                                                                                                                                                
You are in 'detached HEAD' state. You can look around, make experimental                                                                      
changes and commit them, and you can discard any commits you make in this                                                                      
state without impacting any branches by performing another checkout.                                                                         
                                                                                                                                                 
If you want to create a new branch to retain commits you create, you may                                                                       
do so (now or later) by using -b with the checkout command again. Example:                                                                   
                                                                                                                                           
  git checkout -b <new-branch-name>                                                                                                     
                                                                                                                                           
HEAD is now at d195792... clean travis and add linux (#315)                                                                                
localhost:python (d195792*) $ /tmp/ks/pre-env/bin/python setup.py sdist --format=zip                                                    
running sdist                                                                                                                           
removing 'src/' (and everything under it)                                                                                               
creating src                                                                                                                            
creating src/llvm                                                                                                                       
creating src/llvm/utils                                                                                                                 
creating src/llvm/utils/llvm-build                                                                                                      
creating src/llvm/utils/llvm-build/llvmbuild                                                                                          
copying ../../llvm/utils/llvm-build/llvmbuild/configutil.pyc -> src/llvm/utils/llvm-build/llvmbuild                                     
copying ../../llvm/utils/llvm-build/llvmbuild/util.pyc -> src/llvm/utils/llvm-build/llvmbuild                                           
copying ../../llvm/utils/llvm-build/llvmbuild/componentinfo.pyc -> src/llvm/utils/llvm-build/llvmbuild                                            
copying ../../llvm/utils/llvm-build/llvmbuild/main.pyc -> src/llvm/utils/llvm-build/llvmbuild                                                     
copying ../../llvm/utils/llvm-build/llvmbuild/__init__.pyc -> src/llvm/utils/llvm-build/llvmbuild                                        
copying ../../llvm/utils/llvm-build/llvmbuild/util.py -> src/llvm/utils/llvm-build/llvmbuild                                                  
copying ../../llvm/utils/llvm-build/llvmbuild/main.py -> src/llvm/utils/llvm-build/llvmbuild                                            
copying ../../llvm/utils/llvm-build/llvmbuild/configutil.py -> src/llvm/utils/llvm-build/llvm
[...]

localhost:dist (d195792*) $ /tmp/ks/pre-env/bin/pip install ./keystone-engine-0.9.1-3.zip                                                                                                                                                                                       
Processing ./keystone-engine-0.9.1-3.zip                            
Building wheels for collected packages: keystone-engine             
  Running setup.py bdist_wheel for keystone-engine ... done         
  Stored in directory: /home/user/.cache/pip/wheels/99/d4/10/207a426f6fcfca9dfada77be492a7920c67f98909c3e490f01                         
Successfully built keystone-engine                                  
Installing collected packages: keystone-engine                      
Successfully installed keystone-engine-0.9.1.post3                  
/tmp/ks/pre-env/bin/pip install ./keystone-engine-0.9.1-3.zip  280.23s user 19.77s system 527% cpu 56.853 total 
localhost:dist (d195792*) $ /tmp/ks/pre-env/bin/python                                
Python 3.6.2 (default, Oct  2 2017, 16:51:32) 
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keystone
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/ks/pre-env/lib/python3.6/site-packages/keystone/__init__.py", line 4, in <module>
    from .keystone import Ks, ks_version, ks_arch_supported, version_bind, debug, KsError, __version__
  File "/tmp/ks/pre-env/lib/python3.6/site-packages/keystone/keystone.py", line 74, in <module>
    raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.
>>> 

after patch:

localhost:python (d195792) $ git checkout master
localhost:python (master) $ /tmp/ks/post-env/bin/python setup.py sdist --format=zip                                                
running sdist                                                                                                                   
removing 'src/' (and everything under it)                                                                                             
creating src                                                                                                                         
creating src/llvm                                                                                                                       
creating src/llvm/utils                                                                                                                 
creating src/llvm/utils/llvm-build                                                                                                                                                                                                                                              
creating src/llvm/utils/llvm-build/llvmbuild                                                                                          
copying ../../llvm/utils/llvm-build/llvmbuild/configutil.pyc -> src/llvm/utils/llvm-build/llvmbuild                                              
copying ../../llvm/utils/llvm-build/llvmbuild/util.pyc -> src/llvm/utils/llvm-build/llvmbuild  
[...]

localhost:python (master*) $ cd dist 
localhost:dist (master*) $ ls                                       
keystone-engine-0.9.1-3.zip                                         
localhost:dist (master*) $ /tmp/ks/post-env/bin/pip install ./keystone-engine-0.9.1-3.zip                                               
Processing ./keystone-engine-0.9.1-3.zip                            
Building wheels for collected packages: keystone-engine             
  Running setup.py bdist_wheel for keystone-engine ... done         
  Stored in directory: /home/user/.cache/pip/wheels/99/d4/10/207a426f6fcfca9dfada77be492a7920c67f98909c3e490f01                         
Successfully built keystone-engine                                  
Installing collected packages: keystone-engine                      
Successfully installed keystone-engine-0.9.1.post3                  
/tmp/ks/post-env/bin/pip install ./keystone-engine-0.9.1-3.zip  283.91s user 20.02s system 505% cpu 1:00.09 total                       
localhost:dist (master*) $ /tmp/ks/post-env/bin/python                                   
Python 3.6.2 (default, Oct  2 2017, 16:51:32) 
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keystone
>>> 

@edevil
Copy link

edevil commented May 11, 2019

Had this problem today on Ubuntu 18.04.2 LTS.

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

4 participants