0

I tried to use a library (mapnik )and the python binding with it.

The library is installed at D:\install\gis\mapnik-v2.2.0, then I add the following variable to the environment variable through the control panel:

PATH: D:\install\gis\mapnik-v2.2.0\bin;D:\install\gis\mapnik-v2.2.0\lib


PYTHONPATH:D:\install\gis\mapnik-v2.2.0\python\2.7\site-packages

Then I run:

python
>>import mapnik

This worked.

However, I do not want to set the variable to the global environment variable, so I tried to create a bat file like this:

setup_mapnik_path.bat:

SET mapnik_path=D:\install\gis\mapnik-v2.2.0;
SET PATH=%PATH%;%mapnik_path%\lib;%mapnik_path%\bin;
SET PYTHONPATH=%PYTHONPATH%;%mapnik_path%\python\2.7\site-packages; 

Then once I tried to run a script who use mapnik I will run the bat first:

setup_mapnik_path.bat
python
>>import mapnik

But I will get error:

ImportError: No module named mapnik

Screenshot:http://pbrd.co/1lUk1F5

What's the problem?

hguser
  • 31,173
  • 49
  • 145
  • 269
  • Maybe [this](http://stackoverflow.com/a/9546462/2032568) is the issue. – Alex Apr 11 '14 at 03:14
  • Do you mean that the latest set variables will not affect immediately? But I have find that some open source project would set the environment variable in the shell, for example, the tomcat :http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk/bin/catalina.bat – hguser Apr 11 '14 at 03:18
  • Have you tried setting the variables as you are doing and opening a new shell and starting python? It was just a suggestion, I haven't used Windows in a long time to know how it should happen. – Alex Apr 11 '14 at 03:23
  • Since the variables are set through the bat file, I have to run it in the command prompt, I want the variables take affect in the current prompt, once I open a new prompt and do not run the bat again, the variables will not work. – hguser Apr 11 '14 at 03:26

1 Answers1

0

What you listed as your script:

setup_mapnik_path.bat
python
>>import mapnik

just can NOT be a script, because ">>import mapnik" should be a keyboard input, right?

You script should be like this:

call setup_mapnik_path.bat
python

Previous script call the first Batch file that define the variables, then return and execute python. After that, you enter ">>import mapnik" via keyboard.

Aacini
  • 59,374
  • 12
  • 63
  • 94
  • Say that, I have several .py script to run which need set the variable first, so what should I do? for example, there is a script named `run.py`, do I have to modify this script? – hguser Apr 11 '14 at 04:17