How can I install a python package without pip or virtualenv

删除回忆录丶 提交于 2021-01-28 07:09:27

问题


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

回答1:


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...




回答2:


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



来源:https://stackoverflow.com/questions/24267454/how-can-i-install-a-python-package-without-pip-or-virtualenv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!