Import dill failed (but only in my process : No module named ‘dill)

I’m facing a strange situation that I can’t seem to understand: my main program is an application built with PySide6 that launches several QProcesses. I want to use dill.dumps and dill.loads to exchange data between my main program and these QProcesses. Here’s where it gets strange: when I launch the process from the interface (the main program), the import of dill fails in the process (error: No module named ‘dill’)! HOWEVER, this same import works when launching the main program, which uses the same virtual environment and dependencies. The import also works perfectly fine when the process is launched directly from its Python file. Finally, if I replace dill with pickle in my imports and use pickle.dumps and pickle.loads, the imports don’t pose any problems and the process runs perfectly even when launched from the interface. (so I don’t think there’s an issue with a different environment, missing dependencies, or code in launching the QProcess). I should mention that I’m on Windows.
If anyone could help me understand, I would be very grateful.

I’m trying to pass arguments to my QProcess by launching it with the block:

@Slot()
def start_process(self):
    process = QProcess()
    process.readyReadStandardOutput.connect(self.handle_process_stdout)
    process.readyReadStandardError.connect(self.handle_process_stderr)
    process.finished.connect(self.handle_process_finished)
    arg_to_serialize = {"Tracking_Process_sym" : self.starting_tracker.currentText(),
        "Tracking_board_df" : Tracker.all_trackers[self.starting_tracker.currentText()].tracking_board_df}
    arguments = dill.dumps(arg_to_serialize)
    encoded_arg = base64.b64encode(arguments).decode('utf-8')
    process.setProgram(r"C:Python312python.exe")
    process.setArguments([r'testdiil.py', encoded_arg])
    process.setProcessChannelMode(QProcess.MergedChannels)
    process.start()
    self.processes_list.append(process)

Everything works fine with pickle.dumps(arg_to_serialize) but not with dill.dumps(arg_to_serialize). And “I’m encountering the same issue even when I pass no arguments and launch a simple test QProcess like this:

import base64
import sys
import asyncio

try:
    import dill
except Exception as e:
    print(f'Import failed because {e}')

# Object to serialize
data = {'a': 42, 'b': [1, 2, 3], 'c': {'x': 10, 'y': 20}}

# Serialization of the object with Dill
serialized_data = dill.dumps(data)

# Encoding in base64 for transfer as a command-line argument
encoded_data = base64.b64encode(serialized_data).decode('utf-8')

# Decoding from base64 to retrieve serialized data
decoded_data = base64.b64decode(encoded_data)

# Deserialization of the object with Dill
deserialized_data = dill.loads(decoded_data)

# Printing the deserialized object
print(deserialized_data)

New contributor

Alkem is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật