[英]Installing modules without pip in python script
I'm using AnyTree in an independent environment where there is no pip (testcomplete). 我在没有pip(测试完成)的独立环境中使用AnyTree。
I started by moving the anytree folders to the required folders, and started getting import error for six. 我首先将Anytree文件夹移动到所需的文件夹,然后开始出现六个导入错误。 I downloaded six and placed it in as well, and now I get:
我下载了六个文件,并将其放入其中,现在我得到了:
'module' object has no attribute 'iterator'
In case anyone is interested - this is the code for doing this without pip: 如果有人感兴趣-这是无需点子即可执行此操作的代码:
from os import sys
sys.path.insert(0, "C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python34\Lib\site-packages")
import six
import anytree
udo = anytree.Node("Udo")
print(udo)
Any ideas on how to fix this? 有想法该怎么解决这个吗? Google only returned this result: __builtin__.iterator does not exist?
Google仅返回以下结果: __builtin __。iterator不存在?
The only two options I can think of are - moving the folders physically (tried but given the error above) or installing through a script: 我能想到的仅有的两个选择是-物理移动文件夹(尝试过但已给出上述错误)或通过脚本安装:
It doesn't seem to work either (on 2.7 and I tried an updated script on 3.6 but neither work). 它似乎也不起作用(在2.7上,我在3.6上尝试了更新的脚本,但均不起作用)。
import sys
import os
import site
from importlib import reload
try:
import pip
except ImportError:
print "installing pip"
cmd = "sudo easy_install pip"
os.system(cmd)
reload(site)
try:
import requests
except ImportError:
print "no lib requests"
import pip
cmd = "sudo pip install requests"
print "Requests package is missing\nPlease enter root password to install required package"
os.system(cmd)
reload(site)
I wrote something similar before and you are on the right track. 我之前写过类似的文章,而您的方向正确。 Instead of
代替
cmd = "sudo easy_install pip"
you need to try 你需要尝试
cmd = "get-pip.py"
and have it point to the file you can download here https://bootstrap.pypa.io/get-pip.py . 并将其指向文件,您可以在此处下载https://bootstrap.pypa.io/get-pip.py 。
Also, you can run pip from the command line in windows, no need to be in a python terminal. 另外,您可以在Windows的命令行中运行pip,而无需在python终端中运行。 Like So:
像这样:
pip install requests
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.