pkg-resources

How to serve static files in FastAPI

别等时光非礼了梦想. 提交于 2021-02-10 20:57:26
问题 I am trying to serve static files that I have in a package_docs directory. When I open in the browzer: http://127.0.0.1:8001/packages/docs/index.html , the page is running. But I want to open the page: http://127.0.0.1:8001/packages/docs/ without the source file. And the output is 404 Not Found app.mount("/packages/docs", StaticFiles(directory=pkg_resources.resource_filename(__name__, 'package_docs') ), name="package_docs") @app.get("/packages/docs/.*", include_in_schema=False) def root():

Python pkg_resources and file access in packages

China☆狼群 提交于 2020-05-29 07:06:55
问题 I'm building my first python package (which I then install with pip) and I need to use some non-python files. In these answers, it is explained that I should use the pkg_resources function. But I can't figure out a working example. Let say I have this project structure: package_name/ ----data/ --------image.png ----package_name/ --------__init__.py --------file.py ----setup.py ----MANIFEST.in ----conf.yml Now I want to access conf.yml and image.png from file.py . How should I proceed in: file

Accessing files in python egg from inside the egg

Deadly 提交于 2020-01-22 13:56:06
问题 The question is an attempt to get the exact instruction on how to do that. There were few attempts before, which don't seem to be full solutions: solution to move the file inside the package solution to read as zip accessing meta info via get_distribution The task at hand is to read the information about the egg the program is running from. There are few ways as i understand: hard code the location of the egg and treat it as zip archive - will work, but not flexible enough, because it will

Cx_Freeze and Plotly

孤人 提交于 2020-01-11 14:07:43
问题 I am trying to build an exe of an application that uses plotly using cx_freeze. I have previously built the application using matplotlib but have switched the graphing over to plotly. I can build the application but when I try to plot, I get the following error. url = py.plot(fig, filename='pandas-box-plot') File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 284, in p lot get_plotlyjs(), File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 48, in ge t

Why can't `virtualenv` find `pkg_resources`?

六眼飞鱼酱① 提交于 2020-01-01 04:53:09
问题 I'm trying to use virtualenv in Ubuntu to install a local virtual Python environment. When I run the shell command: $ virtualenv ./virt_python It throws an exception that it can't import pkg_resources . But when I open a Python shell and from pkg_resources import load_entry_point it runs fine. For reference, the complete stacktrace is below. $ virtualenv ./virt_python New python executable in ./virt_python/bin/python Installing setuptools............done. Installing pip....... Complete output

Accessing python egg's own metadata

♀尐吖头ヾ 提交于 2019-12-07 06:43:18
问题 I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this: import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) but this would probably work incorrectly if I had multiple versions of the same egg installed. And if I have both installed egg and development version, then running this code from development version would pick up version of the installed egg. So, how do I get metadata for my

Accessing python egg's own metadata

青春壹個敷衍的年華 提交于 2019-12-05 08:26:04
I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this: import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) but this would probably work incorrectly if I had multiple versions of the same egg installed. And if I have both installed egg and development version, then running this code from development version would pick up version of the installed egg. So, how do I get metadata for my egg not some random matching egg installed on my system? I am somewhat new to Python as well, but from

Why can't `virtualenv` find `pkg_resources`?

北战南征 提交于 2019-12-03 13:14:30
I'm trying to use virtualenv in Ubuntu to install a local virtual Python environment. When I run the shell command: $ virtualenv ./virt_python It throws an exception that it can't import pkg_resources . But when I open a Python shell and from pkg_resources import load_entry_point it runs fine. For reference, the complete stacktrace is below. $ virtualenv ./virt_python New python executable in ./virt_python/bin/python Installing setuptools............done. Installing pip....... Complete output from command /home/rpsharp/local/...hon/bin/easy_install /usr/local/lib/pytho...pport/pip-1.1.tar.gz:

Cx_Freeze and Plotly

北城以北 提交于 2019-12-02 08:07:09
I am trying to build an exe of an application that uses plotly using cx_freeze. I have previously built the application using matplotlib but have switched the graphing over to plotly. I can build the application but when I try to plot, I get the following error. url = py.plot(fig, filename='pandas-box-plot') File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 284, in p lot get_plotlyjs(), File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 48, in ge t_plotlyjs plotlyjs = resource_string('plotly', path).decode('utf-8') File "C:\Python34\lib\site-packages\pkg