解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'
利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run'

可以看到是d:\program\python34\lib\site-packages\pipenv\shells.py文件的第62行报错了,提示模块没有run的属性,于是就跑到该文件的第62行去看

选中run,CTRL+B发现能看到源码,源码如下:
if sys.version_info >= (3, 6):
# Nearly same args as Popen.__init__ except for timeout, input, and check
def run(args: _CMD,
timeout: Optional[float] = ...,
input: Optional[_TXT] = ...,
check: bool = ...,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
*,
encoding: Optional[str] = ...,
errors: Optional[str] = ...) -> CompletedProcess: ...
else:
# Nearly same args as Popen.__init__ except for timeout, input, and check
def run(args: _CMD,
timeout: Optional[float] = ...,
input: Optional[_TXT] = ...,
check: bool = ...,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...) -> CompletedProcess: ...
但是请看第一行 if sys.version_info >= (3, 6): ,我们姑且猜测一下,这个3.6就是python的版本号,如果版本大于3.6,就用第一个run函数,否则就用第二个run函数,这两个函数有什么不同——第一个run函数多了下面两行
encoding: Optional[str] = ...,
errors: Optional[str] = ...)
可是,既然版本大于3.6和小于3.6都会调用已存在的run函数,那为什么会报错?我们来看一下比较完整的代码
不知道有没有留意到当版本大于3.5时,才会去第二个if里判断是否大于3.6,而我当前的版本是3.4.4,因此不满足大于3.5的if判断,而满足大于3.3的if判断,此时下面的方法都是call了(事实上,只要满足版本<3.5,都应该调用的是call方法)
if sys.version_info >= (3, 5):
class CompletedProcess:
# morally: _CMD
args = ... # type: Any
returncode = ... # type: int
# morally: Optional[_TXT]
stdout = ... # type: Any
stderr = ... # type: Any
def __init__(self, args: _CMD,
returncode: int,
stdout: Optional[_TXT] = ...,
stderr: Optional[_TXT] = ...) -> None: ...
def check_returncode(self) -> None: ...
if sys.version_info >= (3, 6):
# Nearly same args as Popen.__init__ except for timeout, input, and check
def run(args: _CMD,
timeout: Optional[float] = ...,
input: Optional[_TXT] = ...,
check: bool = ...,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
*,
encoding: Optional[str] = ...,
errors: Optional[str] = ...) -> CompletedProcess: ...
else:
# Nearly same args as Popen.__init__ except for timeout, input, and check
def run(args: _CMD,
timeout: Optional[float] = ...,
input: Optional[_TXT] = ...,
check: bool = ...,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...) -> CompletedProcess: ...
# Same args as Popen.__init__
if sys.version_info >= (3, 3):
# 3.3 added timeout
def call(args: _CMD,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
timeout: float = ...) -> int: ...
else:
def call(args: _CMD,
bufsize: int = ...,
executable: _PATH = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Callable[[], Any] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[_PATH] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...) -> int: ...
了解这个,就知道如何解决了,只要修改源码把run换成call即可(如果要使用3.5及以上的版本,建议把call再换回run)

再次使用pipenv shell,发现可以切换到虚拟环境了

参考文章
https://cuiqingcai.com/5846.html
解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'的更多相关文章
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'
一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'
> 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...
- Centos6.5下安装jumpserver-1.4.1报错AttributeError: module 'gssapi' has no attribute 'GSSException'
报错: >>> import paramiko Traceback (most recent call last): File "<stdin>", ...
随机推荐
- mysql 客户端命令行下 直接查询并导出数据
mysql原来还能这么导出数据,涨知识了. 方式1: select ....(sql语句) INTO OUTFILE '/var/lib/mysql/msg_data.csv ' (导出的文件位置 ...
- 事件对象event之e.targtet || e.srcElement
p.onclick = function (event) { var e = event || window.event, target = e.target ? e.target : e.srcEl ...
- 23种设计模式UML图
- 【我的Android进阶之旅】Android Studio查看Logcat时,如果一行Log太长如何换行显示?
使用Android Studio一段时间了,还有很多小技巧没有掌握.今天又发现了一个比较好用的小技巧,这里分享出来. 1.Android Studio默认显示效果 比如我们用Logcat来查看打印的L ...
- Window mysql 安装配置
1.下载 安装包 mysql-noinstall--winx64.zip 2.解压缩zip包 安装路径 C:\Program Files\MySQL\mysql--winx64 3.配置环境变量 添加 ...
- zabbix-监控Linux服务器
一.zabbix监控 1.关闭防火墙 [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disabl ...
- iOS学习之移除Main.storyboard
每次使用Single View Application模板创建工程之后,总是会有一个Main.storyboard文件,那么,当我们使用代码布局的时候,很显然是不需要它的.那么,如何将它从工程中移除呢 ...
- NHibernate & INotifyPropertyChanged
One of the things that make NHibernate easy to use is that it fully support the POCO model. But one ...
- Bootstrap总结一
参考我的博客:http://www.isedwardtang.com/2017/08/30/bootstrap-primer-1/
- maven Eclipse实战材料整理
最近在看github上面的项目,发现好多的源码都是maven组织的,但又要去使用maven,因此找资料学习,但是效果很不好,直到昨天晚上看了mooc上面的视频,理清了自己的思路,特将资料列表如下: 视 ...