【问题标题】:Intellij: Running python script errors - Fatal Python error: Py_Initialize: unable to load the file system codecIntellij:运行 python 脚本错误 - 致命 Python 错误:Py_Initialize:无法加载文件系统编解码器
【发布时间】:2018-07-03 14:48:11
【问题描述】:

这适用于 Windows Intellij。

  1. 我在 MVN pom 文件中添加了插件 - org.codehaus.mojo,用于设置 PYTHONPATH 环境变量。
  2. 已安装 Python 插件。
  3. 在项目中添加了 python 解释器。

当我运行一个简单的 python 程序时,它会出现以下 2 行错误:

# !/usr/bin/python
print("testing") 

错误:

C:\Users\name\AppData\Local\Programs\Python\Python36\python.exe C:/Users/name/IdeaProjects/projectName/src/main/resources/pythonlib/test.py
Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 1096, in _path_importer_cache
KeyError: 'C:\\Users\\name\\.m2\\repository\\info\\cukes\\cucumber-java\\1.2.2\\cucumber-java-1.2.2.jar'

我已经设置了环境变量 PYTHONHOME、PYTHONPATH 并添加了路径。

这是一个maven项目,在src/main/resources/pythonlib下创建了python文件。

请帮忙。

【问题讨论】:

    标签: python-3.x intellij-idea


    【解决方案1】:

    请试试这个插件配置:

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>python-build</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>C:\Users\name\AppData\Local\Programs\Python\Python36\python.exe</executable>
                    <workingDirectory>src/main/resources/pythonlib/</workingDirectory>
                    <arguments>
                        <argument>test.py</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

    • 谢谢。但这似乎没有帮助
    • 如何运行脚本?你使用“exec”目标吗?
    • 我从 Intellij 运行菜单运行,其中配置的 Python 解释器指向 C:\Users\name\AppData\Local\Programs\Python\Python36\python.exe 和工作目录 C:\用户名\IdeaProjects\src\main\resources\pythonlib
    • 文件“”,第 1074 行,在 _path_hooks NotImplementedError 中:引导问题:python36.zip 包含不带 unicode 标志的非 ASCII 文件名进程完成并退出代码 -1073740791 (0xC0000409)
    • 我已经在windows环境变量中设置了PYTHONPATH和PYTHONHOME。
    猜你喜欢
    • 1970-01-01
    • 2019-02-03
    • 2019-06-02
    • 2015-08-26
    • 2019-11-26
    • 2018-12-13
    • 2011-08-07
    • 2018-11-09
    • 2014-01-16
    相关资源
    最近更新 更多