Python Forum
Having trouble installing self built package and install_requires
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble installing self built package and install_requires
#1
Hi,

I have built a sdist package with python2.7 setup.py sdist. The package is built. However when installing at localmachine, local machine virtual environment or a virtual machine all with Linux MInt 18 and python 2.7 the installation fails when the setup.py install_requires contains anything else than 'nose', e.g.:

config = {
    'name' : 'ksdircmp',
    'description': 'Compare filenames in two directories',
    'author': Name',
    'url': 'Url/project/sdircmp',
    'download_url': 'Where to download it.',
    'author_email': 'mailadress',
    'version' : '0.2',
    'install_requires': ['nose','os'],
    # Adding the following to install_requires make the installtion crash
    #,'os','sys','shutil', 'hashlib', 'argparse','tempfile', 'string', 'random','logging'],
    'packages': ['ksdircmp'],
    'scripts': ['bin/dcmp']
}

setup(**config)
The project structure is: 
Output:
├── bin │   └── dcmp ├── dist │   ├── ksdircmp-0.1.tar.gz │   └── ksdircmp-0.2.tar.gz ├── docs ├── ksdircmp │   ├── __init__.py │   ├── ksdircmp.py │   └── tests │       ├── __init__.py │       └── ksdircmp_tests.py ├── ksdircmp.egg-info │   ├── dependency_links.txt │   ├── PKG-INFO │   ├── requires.txt │   ├── SOURCES.txt │   └── top_level.txt ├── README.rst └── setup.py
If I remove 'os' from install_requires it installs allright. The error message received by
[sudo -H] pip2 install ./dist/ksdircmp-0.2.tar.gz is the following:

Output:
Processing ./dist/ksdircmp-0.2.tar.gz Requirement already satisfied: nose in /usr/local/lib/python2.7/dist-packages (from ksdircmp==0.2) Collecting os (from ksdircmp==0.2)   Using cached os-0.5.tar.gz     Complete output from command python setup.py egg_info:  
Error:
  Traceback (most recent call last):       File "<string>", line 1, in <module>     IOError: [Errno 2] No such file or directory: '/tmp/pip-build-jLDFXg/os/setup.py'          ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-jLDFXg/os/
If I change os to hashlib I receive a similar output. ksdircmp.py imports os and hashlib. bin/dcmp imports os, sys, argparse, shutil and logging and ksdircmp. ksdircmp_test.py imports nose.tools, os,tempfile,shutil, random, string and ksdircmp. I have searched internet but not found any general or applicable information to solve this.  Any help appreciated
 
/blueslow
Reply
#2
Built-in modules don't go into install_requires, only third-party ones.
Reply
#3
Thanks  stranac

How can I find out which modules that are built -in or the oposite?
Where in the package definitions do I specify which modules the package depends on?

/blueslow
Reply
#4
You could start here : https://docs.python.org/2.7/py-modindex.html
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
The easiest way of knowing: if you had to install it separately, it-s a third-party module.

The only third party module you've listed there is nose, and that probably belongs in tests_require, rather than install_requires.
Reply
#6
Quote:[sudo -H] pip2 install ./dist/ksdircmp-0.2.tar.gz is the following:
Is better if you use wheel format.
Command:
python setup.py bdist_wheel
Then is pip install some_module.whl

Quote:You could start here : https://docs.python.org/2.7/py-modindex.html
The point is not knowing what all stuff is in standard library.
Just knowing what's pip installed is enough,
using virtual environment make this a lot easier.
Then pip list pip freeze do show.

Virtual environment is also build in 3.5-->
A quick demo in 3.6.
C:\1                                                                                                           
λ python -m venv some_web_stuff 
C:\1\some_web_stuff
λ C:\1\some_web_stuff\Scripts\activate.bat                             

# Virtualenv is active
(some_web_stuff) C:\1\some_web_stuff                                                                           
λ pip install requests bs4                                                                                     
Collecting requests                                                                                            
  Using cached requests-2.12.4-py2.py3-none-any.whl                                                            
Collecting bs4                                                                                                 
  Using cached bs4-0.0.1.tar.gz                                                                                
Collecting beautifulsoup4 (from bs4)                                                                           
  Downloading beautifulsoup4-4.5.3-py3-none-any.whl (85kB)                                                     
    100% |████████████████████████████████| 92kB 507kB/s                                                       
Installing collected packages: requests, beautifulsoup4, bs4                                                   
  Running setup.py install for bs4 ... done                                                                    
Successfully installed beautifulsoup4-4.5.3 bs4-0.0.1 requests-2.12.4                                          

(some_web_stuff) C:\1\some_web_stuff
λ pip freeze
beautifulsoup4==4.5.3
bs4==0.0.1
requests==2.12.4

(some_web_stuff) C:\1\some_web_stuff
λ pip freeze > requirements.txt
So then in setup.py i would have:
install_requires=['beautifulsoup4', 'requests']
Reply
#7
(Jan-07-2017, 03:39 PM)sparkz_alot Wrote: You could start here : https://docs.python.org/2.7/py-modindex.html
Good.
(Jan-07-2017, 05:49 PM)stranac Wrote: The easiest way of knowing: if you had to install it separately, it-s a third-party module.
Yes that could work for me,if I could remember, but does not necessarily work for somebody else.

(Jan-07-2017, 05:49 PM)stranac Wrote: The only third party module you've listed there is nose, and that probably belongs in tests_require, rather than install_requires.
Yes that is better, but please se below regarding argsparse.

(Jan-07-2017, 06:59 PM)snippsat Wrote: Is better if you use wheel format.
Command:
python setup.py bdist_wheel
Then is pip install some_module.whl
I agree, it's newer and faster, however I did test that and that gave the same error. Therefore I decided to start with sdist to get that working.
(Jan-07-2017, 06:59 PM)snippsat Wrote: The point is not knowing what all stuff is in standard library.
Just knowing what's pip installed is enough,
using virtual environment make this a lot easier.
Then pip list pip freeze do show.
I agree that virtual environment make its easier.

Thanks to all of you, however this does not seem to be the complete solution to specify dependencies. E.g. I added argsparse that is specified  https://docs.python.org/2.7/py-modindex.html it still works to install. With the solutions suggested I can figure it out for my machine, but will it works for other peoples machines if I upload it to PyPi or github and they download it and install it?

/blueslow
Reply
#8
Quote:but will it works for other peoples machines if I upload it to PyPi or github and they download it and install it?
Yes,if you do it right there is no need to download or install anything for user.
It's just pip install mymodule and it will automatic download and install.
I has plain of writing a tutorial about (pip,wheel,setup.py,virtualenv,GitHub,BitBucket and Publish to PyPi).
You can look at this post,which explain it okay.
Reply
#9
(Jan-08-2017, 02:53 PM)snippsat Wrote:
Quote:but will it works for other peoples machines if I upload it to PyPi or github and they download it and install it?
I has plain of writing a tutorial about (pip,wheel,setup.py,virtualenv,GitHub,BitBucket and Publish to PyPi).
You can look at this post,which explain it okay.
Very nice. Thank you!
/blueslow
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020