我已经在虚拟环境中安装了MoviePy
,如下所示:
(env)$: sudo pip install ez_setup
Requirement already satisfied: ez_setup in /usr/local/lib/python2.7/dist-packages
(env)$: sudo pip install moviepy
Requirement already satisfied: moviepy in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: decorator<5.0,>=4.0.2 in /usr/local/lib/python2.7/dist-packages (from moviepy)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from moviepy)
Requirement already satisfied: proglog<=1.0.0 in /usr/local/lib/python2.7/dist-packages (from moviepy)
Requirement already satisfied: requests<3.0,>=2.8.1 in /home/ac3l1k/.local/lib/python2.7/site-packages (from moviepy)
Requirement already satisfied: tqdm<5.0,>=4.11.2 in /usr/local/lib/python2.7/dist-packages (from moviepy)
Requirement already satisfied: imageio<2.5,>=2.0 in /usr/local/lib/python2.7/dist-packages (from moviepy)
Requirement already satisfied: idna<2.8,>=2.5 in /home/ac3l1k/.local/lib/python2.7/site-packages (from requests<3.0,>=2.8.1->moviepy)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /home/ac3l1k/.local/lib/python2.7/site-packages (from requests<3.0,>=2.8.1->moviepy)
Requirement already satisfied: certifi>=2017.4.17 in /home/ac3l1k/.local/lib/python2.7/site-packages (from requests<3.0,>=2.8.1->moviepy)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/ac3l1k/.local/lib/python2.7/site-packages (from requests<3.0,>=2.8.1->moviepy)
Requirement already satisfied: enum34 in /home/ac3l1k/.local/lib/python2.7/site-packages (from imageio<2.5,>=2.0->moviepy)
Requirement already satisfied: futures in /usr/local/lib/python2.7/dist-packages (from imageio<2.5,>=2.0->moviepy)
Requirement already satisfied: pillow in /usr/lib/python2.7/dist-packages (from imageio<2.5,>=2.0->moviepy)
如上面的输出所示,安装成功。
但是,当我在Django项目的models.py
中使用moviepy时,我得到:
ModuleNotFoundError: No module named 'moviepy'
命令pip freeze
为我提供了以下已安装模块的列表:
cffi==1.13.2
cryptography==2.8
dj-database-url==0.5.0
Django==2.2.7
django-extensions==2.2.5
django-filter==2.2.0
django-secure==1.0.1
django-sslserver==0.22
djangorestframework==3.10.3
ez-setup==0.9
Pillow==6.2.1
pkg-resources==0.0.0
pycparser==2.19
pyOpenSSL==19.1.0
pytz==2019.3
six==1.13.0
sqlparse==0.3.0
moviepy
模块不在列表中。为什么?
答案 0 :(得分:3)
在安装moviepy时,您正在使用 sudo
,它会以root用户身份安装软件包,这就是pip在/usr/local/lib/python2.7/dist-packages
文件夹中进行搜索的原因。
在激活环境(env)的情况下, 不要使用 sudo
以安装moviepy,然后将安装该软件包在您的环境中。
答案 1 :(得分:3)
通过在pip install
前面加上sudo
,可以在另一个环境中运行安装,因此基本上可以“停用”安装软件包。
因此,您应该使用以下命令运行它:
(env)$: pip install moviepy
注意:安装软件包时,请切勿使用
sudo
。通过使用sudo
运行它 您授予安装根访问权限。如果程序包中包含恶意代码, 您可以对系统进行更改。您可以使用 改为pip3 install --user packagename
。