Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Unable to import Python module

Đang mở
#757 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với LHIPA.py và chương trình Julia được hiển thị trong issue, sau đó tái hiện ModuleNotFoundError trong môi trường PythonCall được hiển thị. So sánh sys.path được báo cáo và các distribution đã cài đặt với lần thử import; công việc được xem là hoàn tất khi xác định được PythonCall hay việc import module/package là nguyên nhân và ghi lại một cách giải quyết đã được xác minh.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Julia
Star
1.1k
Fork
89
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JuliaPy/PythonCall.jl

Tất cả issue của JuliaPy/PythonCall.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.