系统拥有的Python库

今天,在Windows 10 Ubuntu 子系统中导入serial.threaded抛出异常。

allankliu@allankliu-HP:/mnt/c/LoRaWAN/Python/Gateway$ ./tcp_serial_redirect.py
Traceback (most recent call last):
  File "./tcp_serial_redirect.py", line 12, in <module>
    import serial.threaded
ImportError: No module named threaded
allankliu@allankliu-HP:/mnt/c/LoRaWAN/Python/Gateway$ exit
logout

查找路径时发现python存在不同路径的区别,而且使用pip升级时出现以下情况:

allankliu@allankliu-HP:/$ sudo pip install pyserial --upgrade
Downloading/unpacking pyserial from https://pypi.python.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl#md5=0e555d61700e0b95a15d8162092c5299
  Downloading pyserial-3.4-py2.py3-none-any.whl (193kB): 193kB downloaded
Installing collected packages: pyserial
  Found existing installation: pyserial 2.6
    Not uninstalling pyserial at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed pyserial
Cleaning up...

所谓owned by OS,是因为最初我采用了Ubuntu apt-get管理器安装的原因:

sudo apt-get install python-serial

所以,必须先使用系统软件管理器来卸载,之后采用pip来安装。

sudo apt-get remove python-serial
sudo pip install pyserial

这之后导入软件库正常:

allankliu@allankliu-HP:/$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> import serial.threaded
>>> exit()

这背后的原理,请访问参考网址。

参考网址

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,329评论 12 197
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,980评论 25 709
  • linux和windows下安装python拓展包-pycharm、numpy、scipy、matplotlib、...
    hzyido阅读 81,364评论 2 10
  • 以前的一些收藏,后续再整理格式 如何使用git管理代码版本http://www.cocoachina.com/io...
    安好99阅读 1,059评论 0 4
  • 其实世间哪件事都不易,但没有哪一种事能让你最真切感受在资本市场的战斗,面对是如此血淋淋赤裸裸的人性,努力后的一无所...
    无无行阅读 350评论 0 1