简体   繁体   中英

How can I install a python package without pip or virtualenv

I have to deploy a python application to a production server (Ubuntu) that I do not control nor do I have permissions to apt-get, pip, virtualenv, etc. Currently, its the server is running python 2.6+. I need to install pycrypto as a dependency for the application but given my limited permissions, I'm not sure as to how to do it. The only think I have permissions to do is wget a resource and unpack it or things along those lines.

First off, is it possible to use it without getting it installed in the aforementioned approach? If not, could I download the package then drop in __init__.py files in the pycrypto dir so python knows how to find it like so:

/my_app
  /pycrypto
     /__init__.py
     /pycrypto.py

According to PEP370 , starting with python 2.6 you can have a per-user site directory (see the What's new in Python 2.6? ).

So you can use the --user option of easy_install to install the directory for each user instead of system-wide. I believe a similar option exists for pip too. This doesn't require any privileges since it only uses current user directories.

If you don't have any installer installed you can manually unpack the package into:

~/.local/lib/python2.6/site-packages

Or, if you are on Windows, into:

%APPDATA%/Python/Python26/site-packages

In the case of pycrypto , the package requires building before installation because it contains some C code. The sources should contain a setup.py file. You have to build the library running

python setup.py build

Afterwards you can install it in the user directory by giving:

python setup.py install --user

Note that the building phase might require some C library to already be installed.


If you don't want to do this, the only option is to ship the library together with your application.


By the way: I believe easy_install doesn't really check whether you are root before performing a system wide install. It simply checks whether it can write in the system-wide site directory. So, if you do have the privileges to write there, there's no need to use sudo in the first place. However this would be really odd...

Use easy_install . It should be installed already on Ubuntu for python 2.6+. If not take a look at these install instructions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM