最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Running pyd files with embbedded python on other systems - Stack Overflow

programmeradmin5浏览0评论

So I am writing a python plugin for flow launcher, which has a dependency that uses C extensions compiled into pyd files (sorry if I said it wrong, I'm not super confident on what to call it / how to describe it). The problem I face is that flow launcher requires plugins to be packaged with their dependencies, which leads to errors with the pyd file for the dependency not being found, since there isn't one for the specific os and architecture. (For reference, the dependency I'm talking about is msgspec).

The way dependencies typically work with python plugins for flow, is that they get packaged with a lib folder that includes the dependencies, with the main file of the plugin having something like the following at the top:

import os
import sys

parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, "lib"))

to add the lib folder to path.

Some more things about flow launcher that I should probably mention:

  • Windows Only
  • You can choose the python installation that is used, but by default an embedded version of 3.11 is installed and used

I've tried a couple of things, such as checking to see if the pyd file is not found on startup, and if so, force reinstalling msgspec, however by default flow downloads an embedded version of python 3.11 for python plugins, which doesn't have pip.

After that I tried to install it directly with the setup.py file, with the closest I got being running the following command:

<embedded python executable path> -c "__import__('sys').path.append(str(__import__('pathlib').Path(__import__('os').getcwd()).parent));__import__('sys').path.append(str(__import__('pathlib').Path(__import__('os').getcwd())));import runpy; runpy.run_module('setup')" install

however that installs msgspec globally on their embedded python installation, which could result in version conflicts. Additionally, this is depreciated and doesn't work for all libraries.

I also tried installing all of the pyd files for all supported architectures (still not sure if its even possible), however I only got as far as creating an issue on their github page

Edit: I've found other dependencies that have this same problem, so the solution should work for other dependencies as well

So I am writing a python plugin for flow launcher, which has a dependency that uses C extensions compiled into pyd files (sorry if I said it wrong, I'm not super confident on what to call it / how to describe it). The problem I face is that flow launcher requires plugins to be packaged with their dependencies, which leads to errors with the pyd file for the dependency not being found, since there isn't one for the specific os and architecture. (For reference, the dependency I'm talking about is msgspec).

The way dependencies typically work with python plugins for flow, is that they get packaged with a lib folder that includes the dependencies, with the main file of the plugin having something like the following at the top:

import os
import sys

parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, "lib"))

to add the lib folder to path.

Some more things about flow launcher that I should probably mention:

  • Windows Only
  • You can choose the python installation that is used, but by default an embedded version of 3.11 is installed and used

I've tried a couple of things, such as checking to see if the pyd file is not found on startup, and if so, force reinstalling msgspec, however by default flow downloads an embedded version of python 3.11 for python plugins, which doesn't have pip.

After that I tried to install it directly with the setup.py file, with the closest I got being running the following command:

<embedded python executable path> -c "__import__('sys').path.append(str(__import__('pathlib').Path(__import__('os').getcwd()).parent));__import__('sys').path.append(str(__import__('pathlib').Path(__import__('os').getcwd())));import runpy; runpy.run_module('setup')" install

however that installs msgspec globally on their embedded python installation, which could result in version conflicts. Additionally, this is depreciated and doesn't work for all libraries.

I also tried installing all of the pyd files for all supported architectures (still not sure if its even possible), however I only got as far as creating an issue on their github page

Edit: I've found other dependencies that have this same problem, so the solution should work for other dependencies as well

Share Improve this question edited Jan 22 at 19:52 cibere asked Jan 19 at 13:08 ciberecibere 111 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

For anyone else in the same situation, here is how I solved it:

I used the pip standalone zip application to download pip, install the package, then delete pip

Perma link to code: https://github.com/cibere/flogin/blob/b4619040c1d6cfb19ac211300ecae013cc044454/flogin/pip.py

发布评论

评论列表(0)

  1. 暂无评论