win10的pycharm中安装ansible模块过程
前面的安装报错信息
ansible模块安装报错:Could not install packages due to an OSError: [Errno 2] No such file or directory:
先升级pip版本,如果不指定国内源,容易更新失败
(venv) D:\python_mcw\venv\Scripts>D:\python_mcw\venv\Scripts\python.exe -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
然后设置里安装ansible失败
pip install --index-url https://pypi.tuna.tsinghua.edu.cn/simple/ ansible 设置里执行的命令
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\python_mcw\venv\Scripts\python.exe'.
执行命令还是出现问题:
(venv) D:\python_mcw\venv\Scripts>D:\python_mcw\venv\Scripts\pip.exe install ansible -i https://pypi.tuna.tsinghua.edu.cn/simple/
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ac/17/cb3ae6e4ae5b2d936ec5bf7e20cb91814e3af3ed27bbfcdf8a7253a016d5/ansible-4.8.0.tar.gz (36.1 MB)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-3nnxfuc8\\ansible_b5e66e8954384775acff7f9696d7e583\\ans
ible_collections/amazon/aws/tests/unit/plugins/modules/placebo_recordings/cloudformation/client_request_token_s3_stack/cloudformation.DescribeStackEvents_1.json'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
按照提示是系统不支持长路径,需要打开功能:https://pip.pypa.io/warnings/enable-long-paths
cmd:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
powershell:
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
这里我 桌面上ctrl +shift 右击,打开powershell 执行命令,这个问题就没了,下面是变成另一个问题了
ansible下載地址:https://releases.ansible.com/ansible/
这里我 下载了ansible 2.9.17的包,后面从其它地方下载其它版本包用下面方法安装就成功了
成功安装前的错误信息
我在win10的pycharm上装ansible模块,准备学习写ansible插件用 ,但是pycharm上pip安装不了呀,怎么试都是这个报错,有大佬知道怎么解决吗?我找了网上的信息了,没看到有效的解决方法。
error: can't copy 'lib\ansible\module_utils\ansible_release.py': doesn't
exist or not a regular file
报错详情:
.........
copying lib\ansible\modules\wait_for_connection.py -> build\lib\ansible\modules
copying lib\ansible\modules\yum.py -> build\lib\ansible\modules
copying lib\ansible\modules\yum_repository.py -> build\lib\ansible\module
s
copying lib\ansible\modules_init_.py -> build\lib\ansible\modules
creating build\lib\ansible\module_utils
error: can't copy 'lib\ansible\module_utils\ansible_release.py': doesn't
exist or not a regular file
----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\python_mcw\venv\Scripts\py
thon.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"
'C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-nzxalbzo\ansible-core_305a73fdeb1b456395fe17a9510839d2\setup.py'"'"'; file='"'"'C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-nzxa
lbzo\ansible-core_305a73fdeb1b456395fe17a9510839d2\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup;
setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-gaqrbj71\i
nstall-record.txt' --single-version-externally-managed --compile --install-headers 'D:\python_mcw\venv\include\site\python3.6\ansible-core' Check the logs for full command output.
成功安装的过程
windows下使用pycharm开发基于ansible api的python程序
Window下python安装ansible,基于ansible api开发python程序#
在windows下使用pycharm开发基于ansible api的python程序时,发现ansible的包无法import。本机安装的是3.7.0的python,cmd下使用pip安装ansible一直安装失败。pycharm中使用File | Settings | Project: runTasks | Project Interpreter也无法导入ansible的包。后来终于找到解决方法。
下载ansible压缩包:https://files.pythonhosted.org/packages/ec/ee/1494474b59c6e9cccdfde32da1364b94cdb280ff96b1493deaf4f3ae55f8/ansible-2.7.1.tar.gz
解压到python安装路径下,例如(D:\python_mcw\venv\Scripts\ansible-2.7.1);
以管理员身份运行cmd,cd到上面的安装路径下,输入d:\python_mcw\venv\Scripts\python.exe setup.py install,即可用安装成功;
然后进入pycharm项目中,再次import ansible的包就可以了。
备注:之前用ansible 2.9.17的包还是不行,报错,怀疑是ansible包的问题,于是换成2.7.1的,果然是可以了。
执行成功如下:
Using d:\python_mcw\venv\lib\site-packages
Finished processing dependencies for ansible==2.7.1
前面有个语法报错忽略掉没影响:
File "d:\python_mcw\venv\lib\site-packages\ansible-2.7.1-py3.6.egg\ansible\modules\clustering\openshift\_openshift_scale.py", line 1
../k8s/k8s_scale.py
^
SyntaxError: invalid syntax
安装完之后可以看到python虚拟环境中已经生成了ansible的 目录了D:\python_mcw\venv\Lib\site-packages\ansible-2.7.1-py3.6.egg\ansible
不知道是不是可以直接复制目录到其它虚拟环境使用呢,有时间验证下
进入pycharm,import ansible 没导入成功,关闭pycharm重新打开项目,就可以成功导入ansible模块
这个 模块的安装过程,如果包没有问题,也可以用这个方式安装其它python第三方模块
参考链接:https://www.cnblogs.com/ryxiong-blog/p/11245756.html
某次报错解决过程PyCharm venv失败:“无此选项:--build-dir”
解决方法:
PyCharm依赖于--build- dir
安装软件包,该标志在最新的20.3版中已删除pip
。
PyCharm的修复程序已准备就绪,并将在本周以2020.3版本发布(并移植到2020.2.5和2020.1.5)。
解决方法是降级pip
到以前的版本-关闭PyCharm并python -m pip install pip==20.2.4
使用相应的虚拟环境在终端中运行。
终端上更新了pip,site-包目录下生成pip-21.3.1.dist-info目录
将site-包下的pip和pip-21.3.1.dist-info目录改名,pip -V就找不到模块了
ModuleNotFoundError: No module named 'pip'
把pip目录改回名字,正常返回,并且能正常安装模块,貌似pip-21.3.1.dist-info目录下只有文件,文件是没有用处的。终端上安装之后,setting里面也显示出刚刚装的模块。site-包目录下也多了对应的包目录
(venv) D:\projs\machangwei1\venv\Scripts>pip -V
pip 21.3.1 from D:\projs\machangwei1\venv\lib\site-packages\pip (python 3.6)
虽然pip-21.3.1.dist-info目录没有改回名字,但是setting显示包的地方,下面一行黄色字,python包工具不能找到,安装包工具。
点击安装,事件日志:Packages installed successfully: Installed Python packaging tools。然后黄色字消失,但是site-包目录下多了“pip-10.0.1-py3.6.egg”目录,
pycharm左上角点击关闭项目,所有项目都没关闭,回到刚刚安装然后进入创建项目的页面,此时安装requests模块成功,随便选的那个提示要更新pip,打开原来的machangwei2项目也是可以安装这个模块的
然后按照ansible模块在machangwei2项目上,报错:
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\projs\machangwei2\venv\Scripts\python.exe'.
Command "D:\projs\machangwei2\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Administrator\\AppData\\Local\\Temp\\pycharm-packaging\\cryptography\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-0qjmrtvi\install-record.txt --single-version-externally-managed --compile --install-headers D:\projs\machangwei2\venv\include\site\python3.6\cryptography" failed with error code 1 in C:\Users\Administrator\AppData\Local\Temp\pycharm-packaging\cryptography\
You are using pip version 10.0.1, however version 21.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
可用的包窗口,安装pip.解释器窗口pip还是10版本,但是后面可以的包多了最新版本,选择pip点击右边的升级。升级失败,但是解释器窗口显示 版本是最新,错误信息忘记复制了。重新安装request报错no such option: --build-dir
安装低版本python -m pip install pip==20.2.4
可以看到解释器窗口也成为低版本的了。再次在可用包窗口安装requests模块,成功安装。原来是pip版本问题导致的可用包窗口无法安装模块,即21.3.1版本
参考链接:https://codingdict.com/questions/194677
2.8 ansible AIP开发:https://www.jianshu.com/p/ec1e4d8438e9
2.9 官网api事例:https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html