What is python egg cache

What is the Python egg cache (PYTHON_EGG_CACHE)?

From my investigations it turns out that some eggs are packaged as zip files, and are saved as such in Python’s site-packages directory.

These zipped eggs need to be unzipped before they can be executed, so are expanded into the PYTHON_EGG_CACHE directory which by default is ~/.python-eggs (located in the user’s home directory). If this doesn’t exist it causes problems when trying to run applications.

There are a number of fixes:

  1. Create a .python-eggs directory in the user’s home directory and make it writable for the user.
  2. Create a global directory for unzipping (eg. /tmp/python-eggs ) and set the environment variable PYTHON_EGG_CACHE to this directory.
  3. Use the -Z switch when using easy_install to unzip the package when installing.

Solution 2

The python egg cache is simply a directory used by setuptools to store packages installed that conform to the egg specification. You can read more about setuptools here.

Additionally, as the error message states, you can specify a different egg cache directory in your environment by setting PYTHON_EGG_CACHE=/some/other/dir. The easiest way to do this is to set it in your ~/.bash_profile (assuming you’re using bash), like this:

export PYTHON_EGG_CACHE=/some/other/dir 

You may need to set it in your Apache environment if you’re using a Web application.

Solution 3

This is a dark side-effect of using otherwise nice eggs mechanism.

Читайте также:  Си шарп программирование классы

Eggs are packages (a directory full of files) packed into one .egg file to simplify depolyment.

They are stored in /site-packages/ dir.

As long as the files stored in the egg are .py files it works great. Python import can import things from any file-like object just like it was an ordinary file.

But when something like .so happens to drop in there, python cannot explain to the underlying OS that it wants to load an library which doesn’t have a physical name. And the only workaround distutils authors have thought of is unzipping it into a temp dir. Naturally it is not /site-packages/ since /site-packages/ is not writable for ordinary users.

  • set PYTHON_EGG_DIR to /tmp , or
  • give user www write permission to /var/www/.python-eggs
    (so that the files don’t get unzipped every time /tmp is cleaned up) or better then
  • unzip the egg as suggested by @shalley303
    (and avoid unzipping of the egg in the run-time altogether).

Solution 4

Python eggs are zip-compressed packages containing both Python modules and metadata. The egg cache is where the extracted contents of the egg are stored so that the Python modules contained within are usable.

Solution 5

You can also disable the use of the .egg after it has been installed. You need to go into the site-packages directory, extract the .egg, and then move it to a hidden file (or delete it, or whatever).

Here is an example of what I did to disable the MySQLdb module .egg file which was causing this error when the python script was being run from Zabbix.

cd /usr/local/lib/python2.7/site-packages unzip MySQL_python-1.2.3-py2.7-linux-x86_64.egg mv MySQL_python-1.2.3-py2.7-linux-x86_64.egg .MySQL_python-1.2.3-py2.7-linux-x86_64.egg

Источник

What is the Python egg cache (PYTHON_EGG_CACHE)?

From my investigations it turns out that some eggs are packaged as zip files, and are saved as such in Python’s site-packages directory.

These zipped eggs need to be unzipped before they can be executed, so are expanded into the PYTHON_EGG_CACHE directory which by default is ~/.python-eggs (located in the user’s home directory). If this doesn’t exist it causes problems when trying to run applications.

There are a number of fixes:

  1. Create a .python-eggs directory in the user’s home directory and make it writable for the user.
  2. Create a global directory for unzipping (eg. /tmp/python-eggs ) and set the environment variable PYTHON_EGG_CACHE to this directory.
  3. Use the -Z switch when using easy_install to unzip the package when installing.

Similar question

A simple fix would be to create the directory and provide www-data access to it.

$ mkdir /var/www/.python-eggs $ chown www-data:www-data /var/www/.python-eggs 

Bilal Baqar 208

I got this error in Django when running the below command the first time.

python manage.py sql myproject 

I got it to work like this:

1. In Explorer, view the folder that the error says egg cache directory is set to 2. Delete (or rename) the file mysql_python-1.2.5-py2.7-win32.egg-tmp 3. That's it. The command now works and creates a new file in there. (Haven't tested if I need to do this every time.) 

adding this at the begin of my source file before any import works

import os xyz = os.path.join('~', 'Documents', '.cache') os.environ['PYTHON_EGG_CACHE'] = os.path.expanduser(xyz) 

Phillip B Oldham’s right. You can add these lines in your code:

import os os.environ['PYTHON_EGG_CACHE'] = '/tmp' # a writable directory 

Python eggs are zip-compressed packages containing both Python modules and metadata. The egg cache is where the extracted contents of the egg are stored so that the Python modules contained within are usable.

You can also disable the use of the .egg after it has been installed. You need to go into the site-packages directory, extract the .egg, and then move it to a hidden file (or delete it, or whatever).

Here is an example of what I did to disable the MySQLdb module .egg file which was causing this error when the python script was being run from Zabbix.

cd /usr/local/lib/python2.7/site-packages unzip MySQL_python-1.2.3-py2.7-linux-x86_64.egg mv MySQL_python-1.2.3-py2.7-linux-x86_64.egg .MySQL_python-1.2.3-py2.7-linux-x86_64.egg

This is a dark side-effect of using otherwise nice eggs mechanism.

Eggs are packages (a directory full of files) packed into one .egg file to simplify depolyment.

They are stored in /site-packages/ dir.

As long as the files stored in the egg are .py files it works great. Python import can import things from any file-like object just like it was an ordinary file.

But when something like .so happens to drop in there, python cannot explain to the underlying OS that it wants to load an library which doesn’t have a physical name. And the only workaround distutils authors have thought of is unzipping it into a temp dir. Naturally it is not /site-packages/ since /site-packages/ is not writable for ordinary users.

  • set PYTHON_EGG_DIR to /tmp , or
  • give user www write permission to /var/www/.python-eggs
    (so that the files don’t get unzipped every time /tmp is cleaned up) or better then
  • unzip the egg as suggested by @shalley303
    (and avoid unzipping of the egg in the run-time altogether).

The python egg cache is simply a directory used by setuptools to store packages installed that conform to the egg specification. You can read more about setuptools here.

Additionally, as the error message states, you can specify a different egg cache directory in your environment by setting PYTHON_EGG_CACHE=/some/other/dir. The easiest way to do this is to set it in your ~/.bash_profile (assuming you’re using bash), like this:

export PYTHON_EGG_CACHE=/some/other/dir 

You may need to set it in your Apache environment if you’re using a Web application.

  • What is the best way to keep a sorted list in Python
  • New to macintosh and want to port some of my Python code. What would be the equivalent of Windows Win32api?
  • What is the version of pip installed with python 3.9?
  • What is the proper way to deal with `float(‘nan’)` in Python sets?
  • What is the easiest way to trigger a python script on schedule using Windows 7?
  • What are the consequences the different file structures for installed Python packages?
  • What is the best profiler for python multiprocessing, gevent, greenlets?
  • What is the best way to parallelize a for loop in python (2020)?
  • What is the highest number Python 2.* x86 (i.e.32bit) id() function on Windows x64 can return?
  • What does the ‘put’ keyword do in Python
  • What is the difference between init__ and __init__ in python class?
  • what is the sole purpose of python being an interpreter?
  • What exactly is the python interpreter implemented with?
  • What would be the equivalent of this Python hash writting/accessing code on some lisp languages?
  • What are the downsides to defining a C macro that works like the Python «with» statement?
  • what is the usefulness of ‘>’ in python
  • What is the least resource intense data structure to distribute with a Python Application
  • What does the python operator =- do?
  • python what is the import for threading?
  • What does the .N mean in this block of Python code?
  • What is the alternative for open in python 2.4.3
  • what does the | symbol do in python
  • What are the types of Python operators?
  • In Python 3.6+ what is the f-string to print float 9.9 as string 09.90 and 10 as 10.00?
  • What is the Python equivalent of Perl’s ‘if exists’ for hashes?
  • What is the list comprehension for right triangles in python à la Haskell?
  • What is the extent of the import statement in Python
  • What is the end of string notation in python
  • What is the best way in python to get a denormalized array from this ordered array?
  • How to create buy order using Binance API on python using all my selected coin instead of setting the quantity of what coin I want to buy?

More Query from same tag

  • Multiplying two sets of numbers in python
  • Scrapy Stripping Comma
  • Too many values to unpack (expected 2) while splitting string
  • How to create pairs form python dictionary keys
  • Can’t use results outside of functions
  • How to detect if the letter «a» is in the string of the function?
  • In Python 3, using mysql.connector, passing mysql function in insert
  • Python iterator exception
  • How to copy specific rows from csv file to another csv file based on specific column?
  • Streaming twitter with tweepy returns retweet_count always 0
  • How to calculate how many fields a circle with radius r will take up in a coordinate system
  • Python-MSSQL (pymssql) Set a field Identity Column
  • Workaround for FacialRecognizer class for OpenCV 3.1
  • How can I create a (None,299,299,3) from (299,299,3)?
  • I’m trying to parse a JSON correctly with Python/Django
  • Iteration WAS working in my script, now I cant get python to iterate — what happened?
  • How do I stop Elastic Beanstalk (apparently) removing my downloaded file?
  • Twisted: How to properly check that a request is finished
  • Add more values in a list at once in Python
  • Cleaning user created markdown with code in it
  • I am trying to write a function in python that takes user input and stores it in a list
  • Want to remove object itself from list in Python
  • Python — determine if a word contains a question mark within it
  • Bigram Count using Spark (Python) producing strange output
  • Matplotlib on Jupyter malfunctioning
  • Inverse Filter for Gaussian Blur
  • ‘sqlite3.h’: No such file or directory
  • `plt.legend` in matplotlib, seaborn: How does the `loc` parameter work?
  • Python Selenium Webdriver to open untrusted connections
  • How does Python bypass normal attribute lookup to find `__dict__`?
  • Arrange the list of list in python
  • Why does pycharm not like ‘engine’
  • Async pycurl requests processing for a python beginner
  • Conceptual: Collect «synonyms» from a list of «words»
  • Loop error on Network Analyst (ArcGIS 9.3)

Источник

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