Python install egg module

the python program packed into egg or whl the installation package

the original source :http://www.worldhello.net/2010/12/08/2178.html
this article has been slightly modified.

1.1 install setuptools

first you have to install setuptools tool. Debian/Ubuntu apt installation can be used directly under :

$ sudo apt-get install python-setuptools

or by pip the installation :

$ pip install --upgrade setuptools

or download setuptools the whl package to install. can be found in here, view the latest version for download. after downloading through sh the installation.

$ wget https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl $ pip install setuptools-41.0.1-py2.py3-none-any.whl

it can be used now pip command to install others egg or whl the package.

1.2 make your own egg bag

always install someone else’s egg/whl bag. do you want to make your own bag ? ok, next we will make a simple bag by ourselves 。 first set up the project directory egg-demo, initialize one setup.py file :

$ mkdir egg-demo $ cd egg-demo $ touch setup.py $ ls setup.py

this is mostly padding setup.py。setup.py is actually python kit distutils configuration file, setuptools is based on distutils to do. in setup.py through the setup function to configure the packaging information. the first thing to do is introduce setuptools the function of setup 。 setuptools the setup in fact, is distutils the setup function, fill in setup.py for the following :

$ cat setup.py #!/usr/bin/env python #-*- coding:utf-8 -*- from setuptools import setup setup()

let me write it over here, an empty one egg the configuration file is ready. we can use the following command to generate egg package :

$ python setup.py bdist_wheel

now let’s see what happens :

$ ls -F build/ dist/ setup.py UNKNOWN.egg-info/

you can see three more folders. and in the dist under the folder, there’s one egg file :UNKNOWN-0.0.0-py3.6.egg。 egg production successfully ! let’s look at this egg what format is the file :

$ file dist/UNKNOWN-0.0.0-py3.6.egg dist/UNKNOWN-0.0.0-py3.6.egg: Zip archive data, at least v2.0 to extract

oh, that’s one zip package! ! ok, now let’s look at the interior :

$ unzip -l dist/UNKNOWN-0.0.0-py3.6.egg Archive: dist/UNKNOWN-0.0.0-py3.6.egg Length Date Time Name --------- ---------- ----- ---- 181 2019-07-16 14:43 EGG-INFO/PKG-INFO 132 2019-07-16 14:43 EGG-INFO/SOURCES.txt 1 2019-07-16 14:43 EGG-INFO/dependency_links.txt 1 2019-07-16 14:43 EGG-INFO/top_level.txt 1 2019-07-16 14:43 EGG-INFO/zip-safe --------- ------- 316 5 files

and once again, that’s true whl file view :

$ file dist/UNKNOWN-0.0.0-py3-none-any.whl dist/UNKNOWN-0.0.0-py3-none-any.whl: Zip archive data, at least v2.0 to extract $ unzip -l dist/UNKNOWN-0.0.0-py3-none-any.whl Archive: dist/UNKNOWN-0.0.0-py3-none-any.whl Length Date Time Name --------- ---------- ----- ---- 171 2019-07-16 06:44 UNKNOWN-0.0.0.dist-info/METADATA 97 2019-07-16 06:44 UNKNOWN-0.0.0.dist-info/WHEEL 1 2019-07-16 06:44 UNKNOWN-0.0.0.dist-info/top_level.txt 296 2019-07-16 06:44 UNKNOWN-0.0.0.dist-info/RECORD --------- ------- 565 4 files

and as you can see, whl files and egg the files are different.

Читайте также:  Сложный javascript простым языком

there is only one EGG-INFO folder, containing five egg information file, gone 。 this egg name unknown, version 0.0.0。 it’s because we’re here setup there’s nothing in there. obviously, this egg nothing can be done. so let’s add some more flavor to it. in setup.py , setup the function accepts a set of properties as configuration parameters.

  • name:name is egg the name of the package is also the name of the folder you are looking for to package , the default is UNKNOWN。
  • version: version number, default 0.0.0
  • packages: i’m going to use setuptools another function of theta find_packages, as the name suggests, find_packages used to package files in a specified directory.
  • zip_safe: the default is False, and this happens every time egg the contents of the project file are checked to make sure everything is correct 。

there are also some descriptive attributes, such as description,long_description,author,author_email,license,keywords,platform,url and so on. fill setup.py the following file ::

$ cat setup.py #!/usr/bin/env python #-*- coding:utf-8 -*- from setuptools import setup, find_packages setup( name = "demo", version="0.1.0", packages = find_packages(), zip_safe = False, description = "egg test demo.", long_description = "egg test demo, haha.", author = "amoblin", author_email = "amoblin@ossxp.com", license = "GPL", keywords = ("test", "egg"), platforms = "Independant", url = "", )

in egg-demo directory created and above name directory with the same name demo , demo directory to write __init__.py file :

$ mkdir demo $ cat demo/__init__.py #!/usr/bin/env python #-*- coding:utf-8 -*- def test(): print "Hello, I'm amoblin." if __name__ == '__main__': test()

generate again egg package later view egg package information :

$ python setup.py bdist_egg $ unzip -l dist/demo-0.1.0-py3.6.egg Archive: dist/demo-0.1.0-py3.6.egg Length Date Time Name --------- ---------- ----- ---- 227 2019-07-16 14:50 EGG-INFO/PKG-INFO 164 2019-07-16 14:50 EGG-INFO/SOURCES.txt 1 2019-07-16 14:50 EGG-INFO/dependency_links.txt 1 2019-07-16 14:50 EGG-INFO/not-zip-safe 5 2019-07-16 14:50 EGG-INFO/top_level.txt 111 2019-07-16 14:49 demo/__init__.py --------- ------- 509 6 files

as you can see, there’s an extra folder demo , it has what we wrote __init__.py 。 follow the agile principles, install the experience first :

$ sudo python setup.py install running install running bdist_egg running egg_info writing demo.egg-info/PKG-INFO writing dependency_links to demo.egg-info/dependency_links.txt writing top-level names to demo.egg-info/top_level.txt reading manifest file 'demo.egg-info/SOURCES.txt' writing manifest file 'demo.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py creating build/bdist.linux-x86_64/egg creating build/bdist.linux-x86_64/egg/demo copying build/lib/demo/__init__.py -> build/bdist.linux-x86_64/egg/demo byte-compiling build/bdist.linux-x86_64/egg/demo/__init__.py to __init__.cpython-36.pyc creating build/bdist.linux-x86_64/egg/EGG-INFO copying demo.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying demo.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying demo.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying demo.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO copying demo.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO creating 'dist/demo-0.1.0-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing demo-0.1.0-py3.6.egg removing '/usr/local/lib/python3.6/dist-packages/demo-0.1.0-py3.6.egg' (and everything under it) creating /usr/local/lib/python3.6/dist-packages/demo-0.1.0-py3.6.egg Extracting demo-0.1.0-py3.6.egg to /usr/local/lib/python3.6/dist-packages demo 0.1.0 is already the active version in easy-install.pth Installed /usr/local/lib/python3.6/dist-packages/demo-0.1.0-py3.6.egg Processing dependencies for demo==0.1.0 Finished processing dependencies for demo==0.1.0

at this step, you can also go straight in dist folder, use pip install demo-0.1.0-py3.6.egg command to install. it’s more convenient , because it can also be used when uninstalling pip remove command to uninstall

OK! installed ! and then we can go straight through import to use! !

$ python -c "from demo import test;test()" Hello, I'm amoblin.

successful outcome ! this indicates correct installation. one of our egg the package was born. in general, our source programs are placed in src directory, so next demo folder move to src in the water. but it needs to be modified setup.py files, modifications find_packages the parameter in the function is ‘src’, at the same time increase package_dir parameter :

packages=find_packages('src'), package_dir =

told setuptools in src look for packages in directory instead of the default project root directory 。

Читайте также:  contact form

1.3 egg file uninstall

in order to python3.6 version, for example, egg files are generally installed in /usr/local/lib/python3.6/dist-packages/ directory, there is another directory easy-install.pth file to store the installation egg information :

$ cd /usr/local/lib/python3.6/dist-packages $ cat easy-install.pth|grep demo ./demo-0.1.0-py3.6.egg $ ls -F|grep demo demo-0.1.0-py3.6.egg/

uninstall egg the file is simple and will contain this first egg the line from easy-install.pth delete, and then delete egg folders will do.

Источник

Python .Egg Files: What are They and How to Create Egg Files?

Python Eggs

Python egg is an older version of the Python wheel package containing the metadata and installation information about a particular python package. It is usually present as a .zip file, composed of logical information, resources and source code of a python module or library.

A python egg can be physically encoded but it has been superseded by the python wheel package. Nowadays, python eggs are replaced by python wheel packages which perform the same functions.

Difference between wheel and egg files

Before pip install and wheel packages, .egg files were used for installing and uninstalling python packages from local systems.

As of 2023, Python egg files have completely been replaced by wheel files which have a more defined and structured method of storing metadata and installation resources of python files.

Wheel is a distribution format used for making installations for python. On the other hand, the egg format was both a runtime as well as a distribution package. These files were importable which is unlike python wheel packages.

Wheel packages have an official binary package called the official PyPA specifications, containing a list of all active interrelated specifications. This specification package was preceded by the .PEP 427 official support page.

Читайте также:  Подключить css к хтмл

What Is A Python Egg File

Python Egg File Formats

Python currently supports three different versions of the egg file format.

  • .egg format: This is the file that contains the metadata and source code of a package.
  • .egg-info format: This file contains the metadata of the project located adjacent to the .egg file.
  • .egg-link format : This file is occasionally encountered which is only used to make a reference to a .egg file. This is not an actual file, it just points to the .egg file. They came into existence to make cross platform alternative to links.

Even though .egg format is not used anymore in the newer versions of python, instead , wheel files are used for setup. But regardless we can still create and use egg files in older versions of python by using the setuptools and build modules.

Prerequisites for Creating Egg Files

In order to use the modules, namely, setuptools and build you will need to install them in your system.

The setuptools package helps in easy installation/uninstallation of python tools. It also makes setting up of modules easier and faster. We can also upgrade existing packages with this.

The build module helps in configuring local command line code and in smooth running of commands. You can easily switch between different projects using this module. These tools are only accessible through the project directory.

We will also use the find_packages() function from setuptools.

Now, we have to run the following code to install these two packages in our system.

pip install setuptools pip install 1build

Creating a Python .egg file

Running the code below will create an .egg file for us:

# importing the required modules from setuptools import setup, find_packages #creating a setup file setup( name = "ourfile", version = "0.1", packages = find_packages() )

Now, we have to run the following in the terminal:

After running the above code in the terminal, you should ideally see that there are three new folders that will be created namely,

Note: For many systems, this might give an error because the most widely used distribution package is wheels for the newer versions of python. It is recommended to use wheel files for newer installations and avoid .egg files since they are obsolete as of now.

System Showing Error

Conclusion

The .egg format is suited for easy package installation and also used for upgrading existing modules. It is basically a .zip file that is an older version of the python wheel file . Nowadays, python eggs are obsolete, so it is advisable to create python wheel files so they can be easily used for the newer versions of python. Creating egg files can also raise errors due to version mismatch. To know more about python eggs, visit the official python archive.

Источник

Оцените статью