UMBC CMSC 471 02 Spring 2021 |
• home • about • schedule • hw • exams • notes • colab • github • resources • papers • news • discord • webex • |
471 Python Virtual Environment on GLUsing an aima-python module like logic.py requires not only having access to it, but other aima-python modules (e.g., search.py) that it imports, and several packages (i.e., numpy, ipythonblocks, networkx and sortedcontainers) that need to be installed with pip. We've tried putting all of the required modules (and the ones they require) in your hoework repository, but this does not solve the problem of installing packages. Here's a solution we recommend for current and future ones to let you
For running code on gl, the solution uses a python virtual environment and also the environment variable PYTHONPATH. For use on your own computer might use use PYTHONPATH and forgo setting up a virtual environment. Running 471 python code on GL.UMBC.EDU(1) Use the environment variable PYTHONPATH to have python always look in a copy of the aima-python directory for modules that you import. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules. If you import a module in python it will search for a file in your current directory and then also try each of the directories in the PYTHONPATH variable. Like the Unix PATH variable, it should be a sequence of colon-sperated paths to directories. You can edit your Unix initialization file (e.g., .bashrc or .cshrc) include an environment variable named PYTHONPATH. If you use the bash shell, edit your .bashrc file to include these lines:
If you are using csh or tcsh you will add lines to your .cshrc file like
If you are unsure which shell you are using you can enter the Unix command echo $0 to find out. This directory is a local clone of the aimi-python repository that we'll keep up to date. (2) Use a copy of Python via a virtual environment that has required python packages pre-installed. We've created a python virtual environment that has all of the required python packages that we'll need for 471 installed (e.g., numpy). We'll keep this up to date by installing any new packages that are needed. You can use this version of python by executing one of the following commands, depending on which shell you are usingthis if you are using:
After doing that, whenever you call python in your session, you will get this virtual copy that has the needed packages. If you want to revert to using the regular system python, you can execute the Unix command.
When you logout and log back in, calling python will launch the default version again. If you like, you can add the following to your .bashrc file that will define a new command, aipython, that activates the virtual version of python and then calls it
For csh or tcsh add this to your .cshrc file:
Running 471 python code on your own Unix or mac computer.When using your own computer, creating python virtual environments can be useful if you need different Python configurations that might be inconsistent, but for most of us this is not a problem. So you can probably just use pip to install all of the needed packages in your standard python installation. For hw4, for example, you will need to install numpy, ipythonblocks, networkx, and sortedcontainers. It will still be helpful to setup PYTHONPATH by doing the following.
How you do the second step will vary depending on your operating system: Unix, max osx, or windows. On Unix you call follow the directions we gave for GL above to add/modify your PYTHONPATH variable in your shell configuration file (e.g., .bashrc or .cshrc). On mac osx, the configuration file to modify is .bash_profile. On windows, you can follow these directions to set or update the PYTHONPATH variable, which say:
|
BIT.LY/471s21 • CMSC 471 02 Spring 2021 • CSEE • UMBC |