解决: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>", ...
随机推荐
- 第14章—数据库连接池(C3P0)
spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...
- 安卓使用Canvas绘制工作日程表
有一个项目要使用工作表,选择使用canvas来绘制.实现显示工作日程的选择,可点击加入和取消,效果图:http://jwzhangjie.com/workplan.gif 自己定义控件FormView ...
- 解决linux下python多版本兼容问题?
环境:CentOS 7(7下默认安装python2.7) Pyhon3在CentOS中需要依赖一些其他的包,我们一次性用yum安装一下: yum install zlib-devel bzip2-de ...
- Java io流详解一
原文地址http://www.cnblogs.com/xdp-gacl/p/3634409.html java基础学习总结——流 一.JAVA流式输入/输出原理
- 浅析造成 JS 内存泄露的几种原因及解决方案
内存泄露是指一块被分配的内存既不能使用,又不能回收,直到浏览器进程结束.在C++中,因为是手动管理内存,内存泄露是经常出现的事情.而现在流行的C#和Java等语言采用了自动垃圾回收方法管理内存,正常使 ...
- yum速查
yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包, 能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖 ...
- day3-python的函数及参数
函数式编程最重要的是增强代码的重用性和可读性 1 2 3 4 def 函数名(参数): ... 函数体 ... 函数的定义主要有如下要点: def:表示函数的关键字 函数名:函 ...
- Visio Yoeman
Visio需要确定文件位置才能运行的 Yo主要是用来生成框架的,相当于是一个框架生成器 new install -g generator-django 然后在Visio按F5,选择要创建的环境,就可以 ...
- bat脚本相关
前期准备: 将要执行的脚本名字生成到一个txt文件 首先进入dos运行程序的目录下:输入dir *.jmx /B>FileScript.txt 采用dir *.jmx>list.txt 如 ...
- 通过FFmpeg将多媒体文件解码后保存成Bmp图像(YUV420 RGB32)
/* g++ -o test test.cpp -lavformat -lavcodec -lavutil -lz -lm -lpthread -lswscale */ #include <st ...