简体   繁体   English

模块适用于 cmd 但不适用于 Pycharm

[英]Module works in cmd but not in Pycharm

I am trying to get PostGIS shp2pgsql and pgsql2shp modules to work in PyCharm.我试图让 PostGIS shp2pgsqlpgsql2shp模块在 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.

相关问题 导入 python 模块在 cmd 中有效,但在 IDE (pycharm) 中无效 - Importing a python module works in cmd but not in an IDE (pycharm) 熊猫模块:可在PyCharm中使用,但不能在Terminal中使用 - Pandas Module: Works in PyCharm but not Terminal 我无法在 pycharm 或 CMD 上下载模块“pandas” - I cant download module "pandas" on pycharm or CMD 在 Python 中导入自定义模块 [虽然它在 PyCharm 中有效] - Import Custom Module in Python [Although it works in PyCharm] Python脚本可在PyCharm中运行,但会在Windows cmd中引发路径错误 - Python script works in PyCharm but throws path errors in windows cmd cmd 中的“PermissionError: [Errno 13] Permission denied”,但在 PyCharm 中有效 - “PermissionError: [Errno 13] Permission denied” within cmd, but works in PyCharm 从命令行导入 Python 模块有效,但不能从 PyCharm - Importing a Python module works from command line, but not from PyCharm 在 docker 中运行时没有名为“projecta”的模块,但在 PyCharm 中有效 - No module named 'projecta' when running in docker but works in PyCharm Pycharm “没有名为 REPORT.py 的模块”,但是它存在并且可以工作。 但是之后 - Pycharm “no module named REPORT.py” however it exist and works. But then 在Pycharm中安装Zipline模块有效,但是在尝试使用它时无效 - Installing the Zipline module in Pycharm works but it doesnt work when trying to use it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM