Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Unable to import Python module

未关闭
#757 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
冷清
技术栈
python
领域
tooling

调研方向

从 LHIPA.py 和 issue 中显示的 Julia 程序开始,然后在显示的 PythonCall 环境中复现 ModuleNotFoundError。将报告的 sys.path 和已安装的 distribution 与导入尝试进行比较;完成的标准是确定责任在于 PythonCall 还是模块/package 的导入,并记录一个经过验证的解决方案。

由索引模型根据 Issue 内容生成。

描述

question

To be honest, I'm a little perplexed at how this is failing.

For a background, I need to import a python file that I wrote and is stored in the local directory (LHIPA.py). That file, in turn, needs to import PyWavelets, which has been installed in the .Condapkg environment. I have confirmed in my Julia program as well as in the python file that it is using the python environment created by PythonCall.jl. I've also confirmed, in the Python program, that PyWavelets is an installed package, yet I get this error message: ERROR: Python: ModuleNotFoundError: No module named 'pywavelets'

First the Julia program as well as its output:

...

ENV["JULIA_CONDAPKG_BACKEND"] = "Null"
ENV["JULIA_PYTHONCALL_EXE"] = raw"/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.11'"

using PythonCall
println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
println("\n PythonCall is using", PythonCall.python_executable_path())
println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

 pth = (@__DIR__)        # Path where the python routines are
 pyimport("sys").path.append(pth)  # append path

println("sys.path = ", pyimport("sys").path)
println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
println("ENV['JULIA_CONDAPKG_BACKEND']  = ", ENV["JULIA_CONDAPKG_BACKEND"] )
println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
println("ENV['JULIA_PYTHONCALL_EXE']  = ", ENV["JULIA_PYTHONCALL_EXE"] )

LH = pyimport("LHIPA")

And the output looks as expected:

PythonCall is using/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/bin/python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sys.path = ['/Users/MattPetersonsAccount/.julia/packages/PythonCall/83z4q/pysrc', 
'/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python311.zip', 
'/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.11', 
'/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.11/lib-dynload', 
'/Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.11/site-packages', 
'/Users/MattPetersonsAccount/Documents/Development/PsychoPy/Spatial n-back 2']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ENV['JULIA_CONDAPKG_BACKEND']  = Null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ENV['JULIA_PYTHONCALL_EXE']  = /Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.11'

The Python file, LHIPA.py, looks like this:

from platform import python_version
print("LHIPA python version is: ",python_version())

import importlib_metadata
dists = importlib_metadata.distributions()
for dist in dists:
    name = dist.metadata["Name"]
    version = dist.version
    print(f'found distribution {name}=={version}')
import sys
print("\n",sys.prefix,"\n")

import math
import PyWavelets

And again, the output is as expected:

LHIPA python version is:  3.11.0
found distribution setuptools==82.0.1
found distribution wheel==0.46.3
found distribution importlib_metadata==8.7.1
found distribution pip==26.0.1
found distribution packaging==26.0
found distribution numpy==2.4.4
found distribution PyWavelets==1.9.0
found distribution zipp==3.23.0

 /Users/MattPetersonsAccount/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default 

So, I've confirmed that Julia and Python are using the same environment (unless one of them is reporting incorrectly, or there is an error in front of my eyes I am missing) and I've confirmed that PyWavelets in the Python environment. Yet, I get an import error.

Any ideas? Is there something blatantly obvious that I'm missing?

主要语言
Julia
星标
1.1k
派生
89
平均合并
2 天 15 小时
30 天内合并 PR
7

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

JuliaPy/PythonCall.jl 的其他 Issue

查看 JuliaPy/PythonCall.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。