How can I install the python module YAML without ROOT ACCESS ( 'easy_install' and 'pip' are not available)?

我与影子孤独终老i 提交于 2019-12-11 02:11:38

问题


I am trying to run a python script that calls the yaml module on a server. I only have writing permissions in my home directory. The server has Python 2.7.3 installed. I do not have root access. Also, neither pip nor easy_install are available.

I have downloaded the package and tried to run

python setup.py install --user

which gives the error

error: can't combine user with with prefix/exec_prefix/home or install_(plat)base

How can I get this to work?


回答1:


Setting up and using a virtualenv is almost always a good option and as you indicated you can download virtualenv.py, but that won't run (anymore) without pip being installed because it tries to install wheels. On Linux Mint with Python 2.7.6 the script e.g. throws:

OSError: Command /home/ruamel/venv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools wheel failed with error code 1

You can probably circumvent that by using an older virtualenv.py.

In some other cases it is not feasible to use a virtualenv: e.g. when the system python has all kinds of libraries pre-installed that you need to use and cannot replicate into a local virtualenv. In that case you can download the latest version of ruamel.yaml (of which I am the author) and which is essentially a superset of the PyYAML functionality. When I forked the code I created a setup.py from scratch and it allows you to do

python setup.py install --user 

without problem on the `setup.py extracted from the tar.gz file downloaded from PyPI.




回答2:


Based on the idea of the answer by Anton, these steps worked for me

pip install --user ruamel.yaml

then replace in your script

import yaml

with:

from ruamel.yaml import YAML
yaml=YAML(typ='safe')


来源:https://stackoverflow.com/questions/14866392/how-can-i-install-the-python-module-yaml-without-root-access-easy-install-an

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