程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to easily distribute Python software with Python module dependencies? Python package installation on UNIX is frustrating

編輯:Python

problem :

My goal is to distribute a Python package that has several other widely used Python packages as dependencies. My goal is to distribute a Python package , It includes several other widely used Python Package as a dependency .My package depends on well written, Pypi-indexed packages like pandas, scipy and numpy, and specifies in the setup.py that certain versions or higher of these are needed, eg "numpy >= 1.5". My package relies on well written Pypi Index package , Such as pandas,scipy and numpy, And in setup.py Specifies that some version or later is required , for example “numpy> = 1.5”.

I found that it's immensely frustrating and nearly impossible for Unix savvy users who are not experts in Python packaging (even if they know how to write Python) to install a package like mine, even when using what are supposed to be easy to use package managers. I find , For those who No Python Packaging experts Unix Smart user ( Even if they know how to write Python) To install a package like mine , Even when using the easy-to-use package manager , This is also very frustrating .I am wondering if there is an alternative to this painful process that someone can offer, or if my experience just reflects the very difficult current state of Python packaging and distribution. I wonder if there is a substitute for this painful process , Someone can provide , Or if my experience just reflects Python The current state of packaging and distribution is very difficult .

Suppose users download your package onto their system. Suppose a user downloads your package to their system .Most will try to install it "naively", using something like: Most people will try to “ Naively ” Install it , Use something similar :

$ python setup.py install

Since if you google instructions on installing Python packages, this is usually what comes up. Because if you have information about installing Python Package's google explain , This usually happens .This will fail for the vast majority of users, since most do not have root access on their Unix/Linux servers. This is a failure for the vast majority of users , Because most users Unix / Linux There is no super user access on the server .With more searching, they will discover the "--prefix" option and try: With more search , They will find “--prefix” Options and try :

$ python setup.py install --prefix=/some/local/dir

Since the users are not aware of the intricacies of Python packaging, they will pick an arbitrary directory as an argument to --prefix , eg "~/software/mypackage/" . Because the user does not know Python The complexity of packaging , They will choose any directory as --prefix Parameters of , for example "~/software/mypackage/" .It will not be a cleanly curated directory where all other Python packages reside, because again, most users are not aware of these details. It won't be all the others Python The clean planning directory where the package is located , Because most users don't know these details .If they install another package "myotherpackage", they might pass it "~/software/myotherpackage" , and you can imagine how down the road this will lead to frustrating hacking of PYTHONPATH and other complications. If they install another package “myotherpackage”, They may pass it "~/software/myotherpackage" , You can imagine that this will lead to frustrating PYTHONPATH And other complications of hacking .

Continuing with the installation process, the call to "setup.py install" with "--prefix" will also fail once users try to use the package, even though it appeared to have been installed correctly, since one of the dependencies might be missing (eg pandas, scipy or numpy) and a package manager is not used. Continue with the installation process , Once the user tries to use the package , "setup.py install" Yes "--prefix" Will also fail , Even if it seems to be properly installed , Because one of the dependencies may be lost ( for example pandas,scipy or numpy) And do not use the package manager .They will try to install these packages individually. They will try to install these packages separately .Even if successful, the packages will inevitably not be in the PYTHONPATH due to the non-standard directories given to "--prefix" and patient users will dabble with modifications of their PYTHONPATH to get the dependencies to be visible. Even if it works , By giving "--prefix" Non standard catalog of , The package will inevitably be in PYTHONPATH , And the patient user will be involved in modifying their PYTHONPATH To make dependencies visible .

At this stage, users might be told by a Python savvy friend that they should use a package manager like "easy_install" , the mainstream manager, to install the software and have dependencies taken care of. At this stage ,Python Savvy friends may tell users that they should use mainstream managers "easy_install" Such a package manager installs software and relies on dependencies .After installing "easy_install" , which might be difficult, they will try: install "easy_install" , May encounter difficulties , They will try :

$ easy_install setup.py 

This too will fail, since users again do not typically have permission to install software globally on production Unix servers. This will also fail , Because the user usually has no right to produce Unix Install software globally on the server .With more reading, they will learn about the "--user" option, and try: Read more , They will understand "--user" Options , And try :

$ easy_install setup.py --user 

They will get the error: They will get wrong :

usage: easy_install [options] requirement_or_url ... or: easy_install --helperror: option --user not recognized

They will be extremely puzzled why their easy_install does not have the --user option where there are clearly pages online describing the option. They will be very confused about why their easy_install No, --user Options , There is a clear online page describing this option .They might try to upgrade their easy_install to the latest version and find that it still fails. They may try to easy_install Upgrade to the latest version and find that it still fails .

If they continue and consult a Python packaging expert, they will discover that there are two versions of easy_install , both named " easy_install" so as to maximize confusion, but one part of "distribute" and the other part of "setuptools". If they continue and consult Python Packaging experts , They will find that Two versions Of easy_install , They are called “ easy_install" , To maximize confusion , however “ distribution ” Part of and “setuptools” Another part of .It happens to be that only the "easy_install" of "distribute" supports "--user" and the vast majority of servers/sys admins install "setuptools" 's easy_install and so local installation will not be possible. It happened that there was only "distribute" Of "easy_install" Support "--user" , And most servers / System administrators have installed "setuptools" Of easy_install , Therefore, local installation is not possible .Keep in mind that these distinctions between "distribute" and "setuptools" are meaningless and hard to understand for people who are not experts in Python package management. please remember , For those who are not Python Package management experts , "distribute" and "setuptools" The difference between them is meaningless , It's hard to understand .

At this point, I would have lost 90% of even the most determined, savvy and patient users who try to install my software package -- and rightfully so! At this point , Even the most determined people who try to install my software package , The most astute and patient users , I will also lose 90% - It's a matter of course !They wanted to install a piece of software that happened to be written in Python, not to become experts in state of the art Python package distribution, and this is far too confusing and complex. They want to install one that happens to use Python Software written , Instead of being the most advanced Python Experts in software package distribution , It's too confusing and complicated .They will give up and be frustrated at the time wasted. They give up and get frustrated when they waste time .

The tiny minority of users who continue on and ask more Python experts will be told that they ought to use pip/virtualenv instead of easy_install . Keep asking for more Python A few users of the expert will be told that they should use pip/virtualenv instead of easy_install .Installing pip and virtualenv and figuring out how these tools work and how they are different from the conventional "python setup.py" or "easy_install" calls is in itself time consuming and difficult, and again too much to ask from users who just wanted to install a simple piece of Python software and use it. install pip and virtualenv And figure out how these tools work , And how they compare with traditional "python setup.py" or "easy_install" Calling what is different is itself time-consuming and difficult , And again ask the user who wants to install a simple Python Software and use it .Even those who pursue this path will be confused as to whether whatever dependencies they installed with easy_install or setup.py install --prefix are still usable with pip/virtualenv or if everything needs to be reinstalled from scratch. Even those who pursue this path will be easy_install or setup.py install --prefix Whether the installed dependencies can still be related to pip/virtualenv Use it together , Or wondering if you need to reinstall everything from scratch .

This problem is exacerbated if one or more of the packages in question depends on installing a different version of Python than the one that is the default. If one or more related software packages depend on installing different versions of Python Instead of the default version , Will exacerbate this problem .The difficulty of ensuring that your Python package manger is using the Python version you want it to, and that the required dependencies are installed in the relevant Python 2.x directory and not Python 2.y, will be so endlessly frustrating to users that they will certainly give up at that stage. It is difficult to ensure your Python The package manager uses what you want Python edition , And the required dependencies are installed in the relevant Python 2.x Directory , instead of Python 2.y, For users , It will be endless frustration and will definitely give up at that stage .

Is there a simpler way to install Python software that doesn't require users to delve into all of these technical details of Python packages, paths and locations? Is there a simpler way to install Python Software , There is no need for users to study deeply Python package , All these technical details of the path and location ?For example, I am not a big Java user, but I do use some Java tools occasionally, and don't recall ever having to worry about X and Y dependencies of the Java software I was installing, and I have no clue how Java package managing works (and I'm happy that I don't -- I just wanted to use a tool that happened to be written in Java.) My recollection is that if you download a Jar, you just get it and it tends to work. for example , I am not a big Java user , But I use some occasionally Java Tools , And I don't remember ever having to worry about what I'm installing Java The software X and Y Dependence , And I don't know Java What's going on with the package management ( I'm glad I didn't - I just want to use one that happens to work Java Tools for writing .) My memory is , If you download one Jar, You can get it and it can work .

Is there an equivalent for Python? Is there a Python The equivalent of ?A way to distribute software in a way that doesn't depend on users having to chase down all these dependencies and versions? A way to distribute software in a way that does not depend on all these dependencies and versions that the user must pursue ?A way to perhaps compile all the relevant packages into something self-contained that can just be downloaded and used as a binary? One way is to compile all related packages into self - contained things , Can be downloaded and used as a binary file ?

I would like to emphasize that this frustration happens even with the narrow goal of distributing a package to savvy Unix users, which makes the problem simpler by not worrying about cross platform issues, etc. I assume that the users are Unix savvy, and might even know Python, but just aren't aware (and don't want to be made aware) about the ins and outs of Python packaging and the myriad of internal complications/rivalries of different package managers. I want to emphasize that , Even to the shrewd Unix Narrow goals for users to distribute software packages , This frustration can also happen , This makes the problem simpler , Don't worry about cross platform issues, etc . I think the user is Unix Smart , Maybe even know Python, But I just don't know ( And don't want people to know )Python The details of packaging and the myriad internal complexities of different packaging managers / competition .A disturbing feature of this issue is that it happens even when all of your Python package dependencies are well-known, well-written and well-maintained Pypi-available packages like Pandas, Scipy and Numpy. A disturbing feature of this problem is , Even if all Python Package dependencies are well known , Well written and well maintained Pypi Available packages ( Such as Pandas,Scipy and Numpy), It also happens .It's not like I was relying on some obscure dependencies that are not properly formed packages: rather, I was using the most mainstream packages that many might rely on. It's not like I rely on Fuzzy dependencies that don't properly form packages : contrary , I use the most mainstream packages that many people may rely on .

Any help or advice on this will be greatly appreciated. Any help or advice on this will be greatly appreciated .I think Python is a great language with great libraries, but I find it virtually impossible to distribute the software I write in it (once it has dependencies) in a way that is easy for people to install locally and just run. In my submission Python It's a great language , It has a nice library , But I find it almost impossible to distribute the software I write in a way that is easy for people to install and run locally ( Once it has dependencies ).I would like to clarify that the software I'm writing is not a Python library for programmatic use, but software that has executable scripts that users run as individual programs. What I want to clarify is , The software I am writing is not intended for programmatic use Python library , But software with executable scripts that the user runs as a separate program .Thanks. thank you .


Solution :

Reference resources : https://stackoom.com/en/question/zX5k

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved