对python调包环境的探索:即从哪开始找?

yinhaibo@yinhaibo-OptiPlex-9020:~$ echo $PATH
/home/yinhaibo/anaconda3/bin:/home/yinhaibo/bin:/home/yinhaibo/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd /usr/local/bin
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ cp ~/Videos/test_models/__init__.py __init__.py
cp: cannot create regular file '__init__.py': Permission denied
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ sudo su
[sudo] password for yinhaibo: 
root@yinhaibo-OptiPlex-9020:/usr/local/bin# cp ~/Videos/test_models/__init__.py __init__.py
cp: cannot stat '/root/Videos/test_models/__init__.py': No such file or directory
root@yinhaibo-OptiPlex-9020:/usr/local/bin# cp /home/yinhaibo/Videos/test_models/__init__.py __init__.py
root@yinhaibo-OptiPlex-9020:/usr/local/bin# ^C
root@yinhaibo-OptiPlex-9020:/usr/local/bin# exit
exit
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ ll
total 50560
drwxr-xr-x  2 root root     4096 12月 27 20:38 ./
drwxr-xr-x 10 root root     4096 3月   1  2018 ../
-rwxr-xr-x  1 root root      224 7月  31 15:13 chardetect*
-rwxr-xr-x  1 root root      757 7月  19 15:37 f2py*
-rwxr-xr-x  1 root root      246 7月  24 17:19 freeze_graph*
-rw-r--r--  1 root root       52 12月 27 20:38 __init__.py
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest*
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest2*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython2*
-rwxr-xr-x  1 root root      217 7月  24 17:19 markdown_py*
lrwxrwxrwx  1 root root       28 8月  16 15:01 mindmaster -> /opt/MindMaster-6/MindMaster*
-rwxr-xr-x  1 root root    35097 9月  19 13:54 miniterm.py*
-rw-r--r--  1 root root    36151 9月  19 13:54 miniterm.pyc
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests*
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests-2.7*
-rwxr-xr-x  1 root root      214 7月  24 17:19 pbr*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2.7*
-rwxr-xr-x  1 root root      218 7月  20 16:25 pygmentize*
-rwxr-xr-x  1 root root     2524 9月  19 13:54 rf_monitor.py*
-rw-r--r--  1 root root     2027 9月  19 13:54 rf_monitor.pyc
-rwxr-xr-x  1 root root     5744 9月  18 18:11 rpyc_classic.py*
-rw-r--r--  1 root root     5981 9月  18 18:11 rpyc_classic.pyc
-rwxr-xr-x  1 root root     1691 9月  18 18:11 rpyc_registry.py*
-rw-r--r--  1 root root     2232 9月  18 18:11 rpyc_registry.pyc
-rwxr-xr-x  1 root root      241 7月  24 17:19 saved_model_cli*
-rwxr-xr-x  1 root root      216 9月  18 20:05 stomp*
-rwxr-xr-x  1 root root      226 7月  24 17:19 tensorboard*
-rwxr-xr-x  1 root root 51559400 7月  20 16:04 thrift*
-rwxr-xr-x  1 root root      250 7月  24 17:19 toco*
-rwxr-xr-x  1 root root      254 7月  24 17:19 toco_from_protos*
-rwxr-xr-x  1 root root      212 9月  21 11:13 tqdm*
-rwxr-xr-x  1 root root      212 7月  19 12:28 virtualenv*
-rwxr-xr-x  1 root root      221 9月  21 11:08 wonambi*
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ cd ~
yinhaibo@yinhaibo-OptiPlex-9020:~$ ipython
Python 3.6.5 |Anaconda custom (64-bit)| (default, Apr 29 2018, 16:14:56) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: exit                                                                                                                                                                                                
yinhaibo@yinhaibo-OptiPlex-9020:~$ sudo su
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# pdw
No command 'pdw' found, did you mean:
 Command 'pd' from package 'puredata-core' (universe)
 Command 'pda' from package 'speech-tools' (universe)
 Command 'pdb' from package 'python' (main)
 Command 'cdw' from package 'cdw' (universe)
 Command 'pdv' from package 'alliance' (universe)
 Command 'pwd' from package 'coreutils' (main)
 Command 'psw' from package 'wise' (universe)
 Command 'pdl' from package 'pdl' (universe)
 Command 'paw' from package 'paw-common' (universe)
 Command 'pmw' from package 'pmw' (universe)
pdw: command not found
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# pwd
/home/yinhaibo
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# cp ./Videos/test_models/ /usr/local/bin/test_model
cp: omitting directory './Videos/test_models/'
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# cp ~/Videos/test_models/ /usr/local/bin/test_model
cp: cannot stat '/root/Videos/test_models/': No such file or directory
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# cp /home/yinhaibo/Videos/test_models/ /usr/local/bin/test_model
cp: omitting directory '/home/yinhaibo/Videos/test_models/'
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# cp /home/yinhaibo/Videos/test_models /usr/local/bin/test_model
cp: omitting directory '/home/yinhaibo/Videos/test_models'
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# cp -r /home/yinhaibo/Videos/test_models /usr/local/bin/test_model
root@yinhaibo-OptiPlex-9020:/home/yinhaibo# exit
exit
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd usr
bash: cd: usr: No such file or directory
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd /usr/local/bin/
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ ll
total 50564
drwxr-xr-x  3 root root     4096 12月 27 20:42 ./
drwxr-xr-x 10 root root     4096 3月   1  2018 ../
-rwxr-xr-x  1 root root      224 7月  31 15:13 chardetect*
-rwxr-xr-x  1 root root      757 7月  19 15:37 f2py*
-rwxr-xr-x  1 root root      246 7月  24 17:19 freeze_graph*
-rw-r--r--  1 root root       52 12月 27 20:38 __init__.py
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest*
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest2*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython2*
-rwxr-xr-x  1 root root      217 7月  24 17:19 markdown_py*
lrwxrwxrwx  1 root root       28 8月  16 15:01 mindmaster -> /opt/MindMaster-6/MindMaster*
-rwxr-xr-x  1 root root    35097 9月  19 13:54 miniterm.py*
-rw-r--r--  1 root root    36151 9月  19 13:54 miniterm.pyc
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests*
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests-2.7*
-rwxr-xr-x  1 root root      214 7月  24 17:19 pbr*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2.7*
-rwxr-xr-x  1 root root      218 7月  20 16:25 pygmentize*
-rwxr-xr-x  1 root root     2524 9月  19 13:54 rf_monitor.py*
-rw-r--r--  1 root root     2027 9月  19 13:54 rf_monitor.pyc
-rwxr-xr-x  1 root root     5744 9月  18 18:11 rpyc_classic.py*
-rw-r--r--  1 root root     5981 9月  18 18:11 rpyc_classic.pyc
-rwxr-xr-x  1 root root     1691 9月  18 18:11 rpyc_registry.py*
-rw-r--r--  1 root root     2232 9月  18 18:11 rpyc_registry.pyc
-rwxr-xr-x  1 root root      241 7月  24 17:19 saved_model_cli*
-rwxr-xr-x  1 root root      216 9月  18 20:05 stomp*
-rwxr-xr-x  1 root root      226 7月  24 17:19 tensorboard*
drwxr-xr-x  3 root root     4096 12月 27 20:42 test_model/
-rwxr-xr-x  1 root root 51559400 7月  20 16:04 thrift*
-rwxr-xr-x  1 root root      250 7月  24 17:19 toco*
-rwxr-xr-x  1 root root      254 7月  24 17:19 toco_from_protos*
-rwxr-xr-x  1 root root      212 9月  21 11:13 tqdm*
-rwxr-xr-x  1 root root      212 7月  19 12:28 virtualenv*
-rwxr-xr-x  1 root root      221 9月  21 11:08 wonambi*
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ cd ~
yinhaibo@yinhaibo-OptiPlex-9020:~$ ipython
Python 3.6.5 |Anaconda custom (64-bit)| (default, Apr 29 2018, 16:14:56) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import test_model                                                                                                                                                                                   
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-3e67009ed13b> in <module>
----> 1 import test_model

ModuleNotFoundError: No module named 'test_model'

In [2]: import sys                                                                                                                                                                                          

In [3]: sys.path                                                                                                                                                                                            
Out[3]: 
['',
 '/home/yinhaibo/anaconda3/bin',
 '/home/yinhaibo/anaconda3/lib/python36.zip',
 '/home/yinhaibo/anaconda3/lib/python3.6',
 '/home/yinhaibo/anaconda3/lib/python3.6/lib-dynload',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/IPython/extensions',
 '/home/yinhaibo/.ipython']

In [4]: sys.path.append(0, '/usr/local/bin/')                                                                                                                                                               
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-7341f50b0793> in <module>
----> 1 sys.path.append(0, '/usr/local/bin/')

TypeError: append() takes exactly one argument (2 given)

In [5]: append?                                                                                                                                                                                             
Object `append` not found.

In [6]: help(append)                                                                                                                                                                                        
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-0b77908b9346> in <module>
----> 1 help(append)

NameError: name 'append' is not defined

In [7]: sys.path.insert(0, '/usr/local/bin')                                                                                                                                                                

In [8]: sys.path                                                                                                                                                                                            
Out[8]: 
['/usr/local/bin',
 '',
 '/home/yinhaibo/anaconda3/bin',
 '/home/yinhaibo/anaconda3/lib/python36.zip',
 '/home/yinhaibo/anaconda3/lib/python3.6',
 '/home/yinhaibo/anaconda3/lib/python3.6/lib-dynload',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg',
 '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/IPython/extensions',
 '/home/yinhaibo/.ipython']

In [9]: import test_model                                                                                                                                                                                   

In [10]: from test_model import (pd, np, time)                                                                                                                                                              

In [11]: time.time()                                                                                                                                                                                        
Out[11]: 1545914817.7087874

In [12]: np.linspace(1, 9, 9)                                                                                                                                                                               
Out[12]: array([1., 2., 3., 4., 5., 6., 7., 8., 9.])

着这里尝试将一个自定义包 test_models 放在环境变量中
然后看python执行时能否调包成功

最后结果:未成功

然后我采用增加临时python环境变量的方法将包所在的环境加入。
实验调包成功

其中
import time
import pandas as pd
import numpy as np
为__init__.py 内容

实验发现:python每次执行的搜索环境最稳定是的sys.path

虽然会有当前工作目录的加入但是并不稳定。如果换个工作目录就立刻现原形。

In [13]: exit                                                                                                                                                                                               
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd usr
bash: cd: usr: No such file or directory
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd /usr/local/bin
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ rm -r test_model
rm: descend into write-protected directory 'test_model'? 
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ ll
total 50564
drwxr-xr-x  3 root root     4096 12月 27 20:42 ./
drwxr-xr-x 10 root root     4096 3月   1  2018 ../
-rwxr-xr-x  1 root root      224 7月  31 15:13 chardetect*
-rwxr-xr-x  1 root root      757 7月  19 15:37 f2py*
-rwxr-xr-x  1 root root      246 7月  24 17:19 freeze_graph*
-rw-r--r--  1 root root       52 12月 27 20:38 __init__.py
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest*
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest2*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython2*
-rwxr-xr-x  1 root root      217 7月  24 17:19 markdown_py*
lrwxrwxrwx  1 root root       28 8月  16 15:01 mindmaster -> /opt/MindMaster-6/MindMaster*
-rwxr-xr-x  1 root root    35097 9月  19 13:54 miniterm.py*
-rw-r--r--  1 root root    36151 9月  19 13:54 miniterm.pyc
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests*
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests-2.7*
-rwxr-xr-x  1 root root      214 7月  24 17:19 pbr*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2.7*
-rwxr-xr-x  1 root root      218 7月  20 16:25 pygmentize*
-rwxr-xr-x  1 root root     2524 9月  19 13:54 rf_monitor.py*
-rw-r--r--  1 root root     2027 9月  19 13:54 rf_monitor.pyc
-rwxr-xr-x  1 root root     5744 9月  18 18:11 rpyc_classic.py*
-rw-r--r--  1 root root     5981 9月  18 18:11 rpyc_classic.pyc
-rwxr-xr-x  1 root root     1691 9月  18 18:11 rpyc_registry.py*
-rw-r--r--  1 root root     2232 9月  18 18:11 rpyc_registry.pyc
-rwxr-xr-x  1 root root      241 7月  24 17:19 saved_model_cli*
-rwxr-xr-x  1 root root      216 9月  18 20:05 stomp*
-rwxr-xr-x  1 root root      226 7月  24 17:19 tensorboard*
drwxr-xr-x  3 root root     4096 12月 27 20:42 test_model/
-rwxr-xr-x  1 root root 51559400 7月  20 16:04 thrift*
-rwxr-xr-x  1 root root      250 7月  24 17:19 toco*
-rwxr-xr-x  1 root root      254 7月  24 17:19 toco_from_protos*
-rwxr-xr-x  1 root root      212 9月  21 11:13 tqdm*
-rwxr-xr-x  1 root root      212 7月  19 12:28 virtualenv*
-rwxr-xr-x  1 root root      221 9月  21 11:08 wonambi*
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ rm -r test_model
rm: descend into write-protected directory 'test_model'? yes
rm: descend into write-protected directory 'test_model/__pycache__'? yes 
rm: remove write-protected regular file 'test_model/__pycache__/__init__.cpython-36.pyc'? yes 
rm: cannot remove 'test_model/__pycache__/__init__.cpython-36.pyc': Permission denied
rm: remove write-protected regular file 'test_model/__init__.py'? yes
rm: cannot remove 'test_model/__init__.py': Permission denied
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ ll
total 50564
drwxr-xr-x  3 root root     4096 12月 27 20:42 ./
drwxr-xr-x 10 root root     4096 3月   1  2018 ../
-rwxr-xr-x  1 root root      224 7月  31 15:13 chardetect*
-rwxr-xr-x  1 root root      757 7月  19 15:37 f2py*
-rwxr-xr-x  1 root root      246 7月  24 17:19 freeze_graph*
-rw-r--r--  1 root root       52 12月 27 20:38 __init__.py
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest*
-rwxr-xr-x  1 root root      234 7月  20 16:25 iptest2*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython*
-rwxr-xr-x  1 root root      227 7月  20 16:25 ipython2*
-rwxr-xr-x  1 root root      217 7月  24 17:19 markdown_py*
lrwxrwxrwx  1 root root       28 8月  16 15:01 mindmaster -> /opt/MindMaster-6/MindMaster*
-rwxr-xr-x  1 root root    35097 9月  19 13:54 miniterm.py*
-rw-r--r--  1 root root    36151 9月  19 13:54 miniterm.pyc
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests*
-rwxr-xr-x  1 root root      214 8月  21 16:09 nosetests-2.7*
-rwxr-xr-x  1 root root      214 7月  24 17:19 pbr*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2*
-rwxr-xr-x  1 root root      215 11月 29 13:51 pip2.7*
-rwxr-xr-x  1 root root      218 7月  20 16:25 pygmentize*
-rwxr-xr-x  1 root root     2524 9月  19 13:54 rf_monitor.py*
-rw-r--r--  1 root root     2027 9月  19 13:54 rf_monitor.pyc
-rwxr-xr-x  1 root root     5744 9月  18 18:11 rpyc_classic.py*
-rw-r--r--  1 root root     5981 9月  18 18:11 rpyc_classic.pyc
-rwxr-xr-x  1 root root     1691 9月  18 18:11 rpyc_registry.py*
-rw-r--r--  1 root root     2232 9月  18 18:11 rpyc_registry.pyc
-rwxr-xr-x  1 root root      241 7月  24 17:19 saved_model_cli*
-rwxr-xr-x  1 root root      216 9月  18 20:05 stomp*
-rwxr-xr-x  1 root root      226 7月  24 17:19 tensorboard*
drwxr-xr-x  3 root root     4096 12月 27 20:42 test_model/
-rwxr-xr-x  1 root root 51559400 7月  20 16:04 thrift*
-rwxr-xr-x  1 root root      250 7月  24 17:19 toco*
-rwxr-xr-x  1 root root      254 7月  24 17:19 toco_from_protos*
-rwxr-xr-x  1 root root      212 9月  21 11:13 tqdm*
-rwxr-xr-x  1 root root      212 7月  19 12:28 virtualenv*
-rwxr-xr-x  1 root root      221 9月  21 11:08 wonambi*
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ sudo su
[sudo] password for yinhaibo: 
root@yinhaibo-OptiPlex-9020:/usr/local/bin# rm -r test_model
root@yinhaibo-OptiPlex-9020:/usr/local/bin# rm __init__.py 
root@yinhaibo-OptiPlex-9020:/usr/local/bin# exit
exit
yinhaibo@yinhaibo-OptiPlex-9020:/usr/local/bin$ cd ~
yinhaibo@yinhaibo-OptiPlex-9020:~$ cd Videos/
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ python test_working_dirctory.py 
  File "test_working_dirctory.py", line 3
    a = np.random.randint(1, 9, 9).reshape(3, 3)
    ^
SyntaxError: invalid syntax
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ python test_working_dirctory.py 
[1. 2. 3. 4. 5. 6. 7. 8. 9.]
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ python test_working_dirctory.py 
  File "test_working_dirctory.py", line 4
    a = np.random.randint(1, 9, 9).reshape(3, 3)
    ^
SyntaxError: invalid syntax
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ python test_working_dirctory.py 
[1. 2. 3. 4. 5. 6. 7. 8. 9.]
2018-12-27 21:08-26
a
    0  1  2
0  4  5  8
1  6  1  6
2  2  4  7
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ vim test_working_dirctory.py
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ python test_working_dirctory.py 
[1. 2. 3. 4. 5. 6. 7. 8. 9.]
2018-12-27 21:09-20
a:[[3 1 1]
 [7 4 4]
 [4 6 4]]
    0  1  2
0  3  1  1
1  7  4  4
2  4  6  4
yinhaibo@yinhaibo-OptiPlex-9020:~/Videos$ cd ~
yinhaibo@yinhaibo-OptiPlex-9020:~$ python ./Videos/test_working_dirctory.py 
[1. 2. 3. 4. 5. 6. 7. 8. 9.]
2018-12-27 21:10-02
a:[[3 3 8]
 [7 6 2]
 [4 5 7]]
    0  1  2
0  3  3  8
1  7  6  2
2  4  5  7
yinhaibo@yinhaibo-OptiPlex-9020:~$ mv p
pan.baidu.com/                                    protobuf-3.6.0-cp27-cp27mu-manylinux1_x86_64.whl  python 2018.08.08.ipynb                           
plot_roc.ipynb                                    putty.log                                         
yinhaibo@yinhaibo-OptiPlex-9020:~$ mv ./Videos/test_working_dirctory.py test_working_directory.py
yinhaibo@yinhaibo-OptiPlex-9020:~$ python test_working_directory.py 
Traceback (most recent call last):
  File "test_working_directory.py", line 1, in <module>
    from test_models import (np, pd, time)
ModuleNotFoundError: No module named 'test_models'
yinhaibo@yinhaibo-OptiPlex-9020:~$ 

这里文件存放在哪个位置默认工作目录就在那。

如果说ipython 就是打开 ipython的窗口就是工作目录。

总的来说有必要注意python程序的搜索环境

#对test_working_directory.py 进行修改
增加语句:

import sys
print(sys.path)

首先在/home/yinhaibo/下运行一次

不成功但是可以看到搜索目录是。。。

然后移至Videos中, 再运行。

yinhaibo@yinhaibo-OptiPlex-9020:~$ vim test_working_directory.py 
yinhaibo@yinhaibo-OptiPlex-9020:~$ python test_working_directory.py 
['/home/yinhaibo', '/home/yinhaibo/anaconda3/lib/python36.zip', '/home/yinhaibo/anaconda3/lib/python3.6', '/home/yinhaibo/anaconda3/lib/python3.6/lib-dynload', '/home/yinhaibo/anaconda3/lib/python3.6/site-packages', '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg']
Traceback (most recent call last):
  File "test_working_directory.py", line 3, in <module>
    from test_models import (np, pd, time)
ModuleNotFoundError: No module named 'test_models'
yinhaibo@yinhaibo-OptiPlex-9020:~$ mv test_working_directory.py ./Videos/test_working_directory.py
yinhaibo@yinhaibo-OptiPlex-9020:~$ python ./Videos/test_working_directory.py 
['/home/yinhaibo/Videos', '/home/yinhaibo/anaconda3/lib/python36.zip', '/home/yinhaibo/anaconda3/lib/python3.6', '/home/yinhaibo/anaconda3/lib/python3.6/lib-dynload', '/home/yinhaibo/anaconda3/lib/python3.6/site-packages', '/home/yinhaibo/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg']
[1. 2. 3. 4. 5. 6. 7. 8. 9.]
2018-12-27 21:17-48
a:[[2 4 1]
 [7 3 3]
 [7 8 6]]
    0  1  2
0  2  4  1
1  7  3  3
2  7  8  6
yinhaibo@yinhaibo-OptiPlex-9020:~$ 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值