系统拥有的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 
    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()

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

参考网址

  • http://blog.csdn.net/sinat_21302587/article/details/74279098
  • http://blog.csdn.net/xuezhisdc/article/details/49588517

你可能感兴趣的:(系统拥有的Python库)