简体   繁体   中英

Set environment variable in bat file

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM