Как установить egg python
Перейти к содержимому

Как установить egg python

  • автор:

Как установить egg python

What’s on this Page

.EGG вариант №

Файл EGG, также известный как яйца Python, представляет собой более старый формат дистрибутива Python. Это сжатый архив ZIP с расширением .egg, содержащий исходные файлы приложения Python вместе с метаинформацией о дистрибутиве. Файлы EGG являются альтернативой исполняемым файлам Windows EXE, но являются кроссплатформенными. Этот старый формат для дистрибутивов Python был заменен новым форматом файлов Wheel (WHL) в начале 2010 года.

Формат файла яйца

Файлы EGG сохраняются в виде сжатых ZIP-архивов. Это означает, что если вы замените расширение .egg на .zip, вы сможете открыть его с помощью стандартных утилит распаковки, таких как Corel WinZIP, Microsoft Explorer или RARLAB WinRAR.

Файлы EGG можно создавать с помощью пакета distutils, доступного в Python. Еще одним инструментом, который может создавать и открывать файлы EGG, является SetupTools. Файлы EGG можно установить как пакет с помощью easy_install.

«ПРИМЕЧАНИЕ. Формат файла EGG устарел в пользу нового формата файла колеса WHL».

How to Install Egg File in Python

How to Install Egg File in Python

  1. Use setuptools to Install egg File in Python
  2. Unzip to Install egg File in Python

Long before the pip days, packages were stored as .egg files and were installed via the setuptools component. However, since pip has been introduced to Python, .egg has been replaced by the wheel file, .whl .

If you are working with other packages, there is a possibility to face working with them; though they are deprecated, you can work around them and install the packages stored as .egg files.

In this article, we will discuss how to install the egg file in Python and the tools you can use to achieve this operation.

Use setuptools to Install egg File in Python

Eggs is a distribution format in Python previously used that contains information required by a particular project, from dependencies to environment variables.

Numerous binary formats represent eggs, but the .egg zip file format is the most popular one because it’s useful for sharing projects and simplifies the distribution of Python packages and projects. Alongside the Python code, the .egg file often contains and works with project-wide metadata, C extensions, and package-specific data.

With .egg files, you don’t need to build or install it per se; you need to add it to your sys.path , but it might often require runtime files. Like the popular Python requirement, requirements.txt and .egg files allow the libraries’ specifications to be stated within.

If you happen to need to work with a .egg file and need the non-Python data files, you need to install the .egg file. To install Python Eggs, you can make use of easy_install .

We will base all operations within the Python 2.7 environment on Windows for all the operations here to work.

To access easy_install , you need to install the setuptools package, which helps to download, install, manage, build or remove Python packages.

To install setuptools , we need to download the ez_setup.py from the setuptools package page.

After downloading the Python file, you transfer it to the Python27 directory, which would most likely be C:\Python27 . Now, open your command prompt, change the directory to C:\Python27 and set the PYTHON_PATH .

set PYTHON_PATH=c:\Python27 set Path=C:\Python27\Scripts 

Now, run the following command to install the setuptools package.

python.exe ez_setup.py 

The easy_install.exe command is now installed and can be used to install an egg file within your Python 2.7 environment.

Because egg files are now deprecated, it can be hard to find one to show as an example, but we can still create them using the setuptools module.

In our case, we will create an empty egg file with the name delftscope . To create such, we need to create a setup.py file that contains the following code.

from setuptools import setup, find_packages  setup(name="delftscope", version="0.1", packages=find_packages()) 

Afterward, we can run the following python command, which creates the egg file alongside other directories. These directories include build , dist , and delftscope.egg-info .

python setup.py bdist_egg 

Within the dist directory, you will find the egg file with the name delftscope-0.1-py3.10.egg .

Now that we have an egg file to work with let’s use the easy_install program to install it. Since we have added it to the OS environment using the set command, we should be able to use easy_install anywhere.

To install the egg file in Python, you can use the following command within your PowerShell.

easy_install .\delftscope-0.1-py3.10.egg 
Processing delftscope-0.1-py3.10.egg Copying delftscope-0.1-py3.10.egg to c:\python27\lib\site-packages Adding delftscope 0.1 to easy-install.pth file  Installed c:\python27\lib\site-packages\delftscope-0.1-py3.10.egg Processing dependencies for delftscope==0.1 Searching for delftscope==0.1 Reading https://pypi.python.org/simple/delftscope/ 

With this, you would have installed the module packaged within the egg file. However, Python has moved to the wheel distribution format.

Unzip to Install egg File in Python

Egg files are zip files; therefore, you can unzip this file. So, if you are on Linux, you can use the unzip package to extract its content and then use the setup.py to install the package that’s held within the egg file.

To unzip the egg file, the unzip command can be used.

unzip -l delftscope-0.1-py3.10.egg 

Afterward, you can access the contents and run the python command to install the package.

python setup.py install 

Olorunfemi is a lover of technology and computers. In addition, I write technology and coding content for developers and hobbyists. When not working, I learn to design, among other things.

Copyright © 2024. All right reserved

How exactly does one install `.egg` files?

When I tried downloading the Sphinx installer here, my computer couldn’t find a default application to run the installer. easy_install doesn’t work either. I’m running Python 2.7 but only have easy_install for 2.5 and 2.6 Furthermore, the analogous one for 2.7 is an .egg file.

54.4k 21 21 gold badges 165 165 silver badges 213 213 bronze badges
asked Jul 5, 2012 at 1:08
183 1 1 gold badge 1 1 silver badge 5 5 bronze badges
I’m running Mac OS 10.6.8.
Jul 5, 2012 at 1:32

I think easy_install has been replaced by pip, try pip install sphinx . Also, the egg file is just a zip, so you could unzip it and then use python setup.py install .

Jul 5, 2012 at 17:34

unzip setuptools-0.6c11-py2.7.egg didn’t work after I downloaded the .egg, and I still can’t open it. Am I doing something wrong?

Jul 5, 2012 at 17:57

Oh, Sphinx’ egg is a zip file, but setuptools seems like a bash file, here says to run as sh setuptools-0.6c11-py2.7.egg —prefix=~

Jul 5, 2012 at 18:02

I did that as well — it says that there’s no such file or directory (I couldn’t unzip sphinx either).

Jul 5, 2012 at 18:16

3 Answers 3

The .egg file may be generated as part of the installation, rather than used to perform the installation. In that instance, the installation package is a directory with the following (or similar) structure.

my_project/ my_module/ __init__.py tests/ __init__.py setup.py 

With the Anaconda Distribution of python, the installation can then be performed within Anaconda Prompt. If a virtual environment is used, it should first be activated.

conda activate C:\[path]\virtual_environment_name 

The setup.py file included in the command to perform the installation may require a specific version of the setuptools python library. Even earlier versions of python tend to be bundled with the latest setuptools library, which may not be compatible with the required setup.py file. If compatibility issues are encountered, the following setuptools version installation within Anaconda Prompt may resolve them (with the virtual environment activated, if applicable).

pip install setuptools==58.2.0 

One must then navigate to the package directory within Anaconda Prompt (with the virtual environment activated, if applicable).

cd C:\[path]\my_project 

Then, the following command is used.

python setup.py install 

Once the installation is complete, an .egg file may be present inside the python packages directory (the file will have been generated as part of the installation). A python interpreter can then load python modules directly from the .egg file.

Chapter 38 — The Python egg¶

Python eggs are an older distribution format for Python. The new format is called a Python wheel, which we will look at in the next chapter. An egg file is basically a zip file with a different extension. Python can import directly from an egg. You will need the SetupTools package to work with eggs. SetupTools is the original mainstream method of downloading and installing Python packages from PyPI and other sources via the command line, kind of like apt-get for Python. There was a fork of SetupTools called distribute that was eventually merged back into SetupTools. I only mention it because you may see references to that fork if you do much reading about Python eggs outside of this book.

While the egg format is being migrated away from, you do still need to know about it as there are many packages that are distributed using this technology. It will probably be years before everyone has stopped using eggs. Let’s learn how to make our own!

Creating an egg¶

You can think of an egg as just an alternative to a source distribution or Windows executable, but it should be noted that for pure Python eggs, the egg file is completely cross-platform. We will take a look at how to create our own egg using the package we created in a previous modules and packages chapter. To get started creating an egg, you will need to create a new folder and put the mymath folder inside it. Then create a setup.py file in the parent directory to mymath with the following contents:

from setuptools import setup, find_packages setup( name = "mymath", version = "0.1", packages = find_packages() ) 

Python has its own package for creating distributions that is called distutils. However instead of using Python’s distutils’ setup function, we’re using setuptools’ setup. We’re also using setuptools’ find_packages function which will automatically look for any packages in the current directory and add them to the egg. To create said egg, you’ll need to run the following from the command line:

c:\Python34\python.exe setup.py bdist_egg 

This will generate a lot of output, but when it’s done you’ll see that you have three new folders: build, dist, and mymath.egg-info. The only one we care about is the dist folder in which you will find your egg file, mymath-0.1-py3.4.egg. Note that on my machine, I forced it to run against Python 3.4 so that it would create the egg against that version of Python. The egg file itself is basically a zip file. If you change the extension to “zip”, you can look inside it and see that it has two folders: mymath and EGG-INFO. At this point, you should be able to point easy_install at your egg on your file system and have it install your package.

Wrapping Up¶

Now it’s your turn. Go onto the Python Package Index and find some pure Python modules to download. Then try creating eggs using the techniques you learned in this chapter. If you want to install an egg, you can use easy_install. Uninstalling an egg is a bit tougher. You will have to go to its install location and delete the folder and / or egg file it installed as well as remove the entry for the package from the easy-install.pth file. All of these items can be found in your Python’s site-packages folder.

© Copyright 2017, Michael Driscoll.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *