无法将python模块导入根目录,仅特定目录可用于导入模块

时间:2019-06-02 19:17:09

标签: python python-2.7 centos7

我已经安装了vps centos7。我正在使用python2.7运行一些脚本。但是问题出在某些目录中,我可以使用python通用模块(例如请求)。但是在根目录下,我无法导入python请求模块。它说没有模块名称 python请求 。但是我在VPS的另一个目录上使用它。

[root@madcodlab-centos7 site-packages]# ls                                                                                                                                                           
backports                                            _dummy_thread                    ipaddress.pyc                   pushetta-1.0.15.dist-info                 terminaltables-3.1.0-py2.7.egg-info  
backports.ssl_match_hostname-3.5.0.1-py2.7.egg-info  easy_install.py                  ipaddress.pyo                   python_linux_procfs-0.4.9-py2.7.egg-info  _thread                              
builtins                                             easy_install.pyc                 libfuturize                     pyudev                                    tkinter                              
certifi                                              easy_install.pyo                 libpasteurize                   pyudev-0.15-py2.7.egg-info                tuned                                
certifi-2019.3.9.dist-info                           examples                         _markerlib                      queue                                     urlgrabber                           
chardet                                              firewall                         _markupbase                     reprlib                                   urlgrabber-3.10-py2.7.egg-info       
chardet-3.0.4.dist-info                              future                           paho                            requests                                  urllib3                              
configobj-4.7.2-py2.7.egg-info                       future-0.17.1-py2.7.egg-info     paho_mqtt-1.4.0-py2.7.egg-info  requests-2.22.0.dist-info                 urllib3-1.25.3.dist-info             
configobj.py                                         html                             past                            rpmUtils                                  validate.py                          
configobj.pyc                                        http                             pip                             setuptools                                validate.pyc                         
configobj.pyo                                        idna                             pip-8.1.2-py2.7.egg-info        setuptools-0.9.8-py2.7.egg-info           validate.pyo                         
copyreg                                              idna-2.8.dist-info               pkg_resources.py                slip                                      winreg                               
decorator-3.4.0-py2.7.egg-info                       iniparse                         pkg_resources.pyc               slip-0.4.0-py2.7.egg-info                 xmlrpc                               
decorator.py                                         iniparse-0.4-py2.7.egg-info      pkg_resources.pyo               slip.dbus-0.4.0-py2.7.egg-info            yum                                  
decorator.pyc                                        ipaddress-1.0.16-py2.7.egg-info  procfs                          socketserver                                                                   
decorator.pyo                                        ipaddress.py                     pushetta                        terminaltables 

[root@madcodlab-centos7 site-packages]# python                                                                                                                                                       
Python 2.7.16 (default, May 24 2019, 21:44:39)                                                                                                                                                       
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2                                                                                                                                                    
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                               
>>> import requests                                                                                                                                                                                  
>>> exit()               

[root@madcodlab-centos7 site-packages]# cd 

[root@madcodlab-centos7 ~]# python                                                                                                                                                                   
Python 2.7.16 (default, May 24 2019, 21:44:39)                                                                                                                                                       
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2                                                                                                                                                    
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                               
>>> ex                                                                                                                                                                                             
>>> import requests                                                                                                                                                                                  
Traceback (most recent call last):                                                                                                                                                                   
  File "<stdin>", line 1, in <module>                                                                                                                                                                
ImportError: No module named requests                                                                                                                                                                
>>>                                                                                                                                                                                                  

我从网上到处搜索并厌倦了很多解决方案,但似乎无济于事。

which python产生/usr/local/bin/python

网站软件包目录为/usr/lib/python2.7/site-packages

0 个答案:

没有答案