Recently, I was working in Python and trying to install the pandas module using the pip command, but kept getting an error like this:
InstallationError: Command python setup.py egg_info failed with error code 1 in /var/www/python/virtualenv
I spent about two hours trying to figure out how to resolve this issue and wanted to share my solution with you here.
To summarize, I downloaded the necessary package using apt-get and then moved the module into my virtual environment via bash command. So, even if you did not experience the same error message as me, this post might be helpful if you’re just looking to move modules from the general Python directory into your virtual environment.
For those looking to get a better understanding of the difference between apt-get and pip, I recommend Aditya’s answer on this StackOverflow post (I don’t have much experience in this).
For those looking to resolve the error:
- To start, you need to install the desired module using the apt-get command. For pandas, that’s this:
sudo apt-get install python-pandas
This installs the module in a system-wide location on your server.
- Find where your recently-downloaded module is located on the server. It should be in your dist-packages directory under your installation of Python.
The complete path for me was located at /usr/lib/python2.7/dist-packages.
You can also launch Python using the command python –v and see where all the different loaded packages reside upon start-up of the application.
- Create a directory for the module in your virtual environment:
cd /var/www/python/virtualenv/lib/python2.7/site-packages && mkdir pandas
- Now move all files from the system-wide module directory into your virtual environment:
mv /usr/lib/python2.7/dist-packages/pandas/* /var/www/python/virtualenv/lib/python2.7/site-packages/pandas/
And that’s it! You should now be able to access the module in your virtual environment. You can verify this by launching your virtual environment version of Python and attempting to import the module. No errors means success.
Do note that given discrepancies between apt-get and pip, the version of the module you transferred may not be the most recent version available.
Also, this might not be the best solution for your problem! I was stuck on the error for a long time and opted for a workaround like this to alleviate my issues after trying a number of different recommendations across the web. If you find a better solution, please forward it my way.