[英]Module works in cmd but not in Pycharm
I am trying to get PostGIS shp2pgsql
and pgsql2shp
modules to work in PyCharm.我试图让 PostGIS shp2pgsql
和pgsql2shp
模块在 PyCharm 中工作。 I can get them to work in the command prompt with no problems but not in a run of my script in PyCharm:我可以让它们在命令提示符下正常工作,但不能在 PyCharm 中运行我的脚本:
'shp2pgsql' is not recognized as an internal or external command, operable program or batch file. 'shp2pgsql' 不是内部或外部命令,也不是可运行的程序或批处理文件。
Most similar google search found is pycharm and subprocess - what works in console doesn't work in Pycharm , but it is not exactly the same.找到的最相似的谷歌搜索是pycharm 和 subprocess - 在控制台中起作用的在 Pycharm 中不起作用,但并不完全相同。
I have set the path variable within PyCharm according to https://www.jetbrains.com/help/pycharm/absolute-path-variables.html , but the same error is reproduced.我已经根据https://www.jetbrains.com/help/pycharm/absolute-path-variables.html在 PyCharm 中设置了路径变量,但重现了相同的错误。
Here is my code:这是我的代码:
import time
import subprocess
command = 'shp2pgsql -I -d -s 27001 //d10/t/ca/analysis/road/extents/ne_extent.shp d.extent_ne| psql -q -d projects -h postgres.local'
process = subprocess.Popen(command, shell=True)
while process.poll() is None:
time.sleep(0.5)
I'm using PyCharm version 2019.3.1 in Windows 10.我在 Windows 10 中使用 PyCharm 版本 2019.3.1。
Go to Settings --> Tools --> Terminal --> project Settings and add in a new Environment Variable specifying the bin folder location of postgis.转到设置 --> 工具 --> 终端 --> 项目设置并添加一个新的环境变量,指定 postgis 的 bin 文件夹位置。 I also changed the start directory to C:\\ instead of the path to the PyCharm project that I am currently working on.我还将启动目录更改为 C:\\ 而不是我目前正在处理的 PyCharm 项目的路径。 Not entirely sure which did the job, but it works now.不完全确定哪个完成了这项工作,但它现在有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.