In Listing 13.11, once the directory is created, cd is used to change the present working directory to
the location of the tested module on line 5. The arith.py module file is then copied to the
production directory on line 7, using the sudo and cp commands.
By the Way: Don’t Want a Copy?
If you do not want or need to keep a copy of your newly created module in your test
directory, you can use the mv (move) command. Simply replace cp with the mv
command, and the module is moved to the production directory, with no copy of it left
in the test directory.
Now that the module has been copied to the production directory, you should be able to import the
arith module, right? Well, look at Listing 13.12.
LISTING 13.12 Module arith Not Found
Click here to view code image
$ python3
...
>>> import arith
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named arith
>>>
Obviously, there is a problem with Python finding the module. You can resolve this problem in the
next step.
Checking the Path and Modifying It, if Needed
It is a good idea to check your current Python path directories. As shown in Listing 13.10, the two
commands to use are import sys and sys.path. Notice in Listing 13.13 that the production
directory /usr/local/lib/python3.2/site-packages is not listed. This is why Python
could not find the arith module file.
LISTING 13.13 Checking the Python Path Directories
Click here to view code image
>>> import sys
>>> sys.path
['', '/usr/lib/python3.2', '/usr/lib/python3.2/plat-linux2',
'/usr/lib/python3.2/lib-dynload',
'/usr/local/lib/python3.2/dist-packages',
'/usr/lib/python3/dist-packages']
>>>
To modify the path, if needed, you use a function from the sys module, as shown in Listing 13.14.