I'm trying to add Seaborn dependency to my module, using Poetry.
I've tried it on different ways, but always without success, maybe I'm doing it wrong.
Here's my current toml config file:
[tool.poetry]
name = "seaborn"
version = "0.1.0"
description = ""
authors = ["me"]
[tool.poetry.dependencies]
python = "3.9.6"
pandas = "^1.4.1"
jupyter = "^^.0.0"
scipy = "1.7.0"
numpy = "^1.22.3"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
I've tried on the CLI:
poetry add seaborn
But no success.
Here's the output
poetry add seaborn
Using version ^0.11.2 for seaborn
Updating dependencies
Resolving dependencies... (0.0s)
AssertionError
at ~/.pyenv/versions/3.10.0/lib/python3.10/site-packages/poetry/mixology/incompatibility.py:111 in __str__
107│ )
108│
109│ def __str__(self):
110│ if isinstance(self._cause, DependencyCause):
→ 111│ assert len(self._terms) == 2
112│
113│ depender = self._terms[0]
114│ dependee = self._terms[1]
115│ assert depender.is_positive()
If I try to add it to the toml config file like seaborn = "^0.0.1"
The out put is very similar:
poetry update
Updating dependencies
Resolving dependencies... (0.0s)
AssertionError
at ~/.pyenv/versions/3.10.0/lib/python3.10/site-packages/poetry/mixology/incompatibility.py:111 in __str__
107│ )
108│
109│ def __str__(self):
110│ if isinstance(self._cause, DependencyCause):
→ 111│ assert len(self._terms) == 2
112│
113│ depender = self._terms[0]
114│ dependee = self._terms[1]
115│ assert depender.is_positive()
Can anyone help me?
Thank you so much!
After a few hours of dropping modules/restarting Pycharm / Invalidating cache... My project is up-to date without any issue!
For future note:
Do not name your modules/scripts with an already existing package (eg: scipy, seaborn, and so on)
I cannot comment yet, so need to supply a new answer.
This issue has broad applicability beyond just the Seaborn module and should be renamed something like, "Cannot add package using Poetry, AssertionError incompatibility.py:111".
The existing Answer, by #diguex, that I up-voted is exactly the fix needed and this answer helped me with the same problem, attempting to import 'flask-restx' into a demo project named 'flask-restx'.
Long and short, Poetry cannot import a dependency into itself. Naming the module with an already existing package name will confuse Poetry into thinking it is doing just that. For more discussion, see: https://github.com/python-poetry/poetry/issues/3491
Related
I'm giving a shot to the pyproject.toml file, and I'm stuck on this simple task. Consider the following optional dependencies:
[project.optional-dependencies]
style = ["black", "codespell", "isort", "flake8"]
test = ["pytest", "pytest-cov"]
all = ["black", "codespell", "isort", "flake8", "pytest", "pytest-cov"]
Is there a way to avoid copy/pasting all the optional-dep in the all key? Is there a way to do all = style + test at least?
There is no such feature directly in the toml markup.
However, there is a tricky way to do this in Python packaging by depending on yourself:
[project.optional-dependencies]
style = ["black", "codespell", "isort", "flake8"]
test = ["pytest", "pytest-cov"]
all = ["myproject[style]", "myproject[test]"]
Source:
Circular dependency is a feature that Python packaging is explicitly designed to allow, so it works and should continue to work.
We've been using pipenv for dependency management for a while, and using micropipenv's protected functionality to check lock freshness - the idea here being that micropipenv is lightweight, so this is a cheap and cheerful way of ensuring that our dependencies haven't drifted during CI or during a docker build.
Alas, micropipenv has no such feature for poetry (it skips the hash check completely), and I am therefore left to "reverse-engineer" the feature on my own. Ostensibly this should be super easy - I've assembled the code posted later from what I traced through the poetry and poetry-core repos (Locker, Factory, core.Factory, and PyProjectTOML, primarily). This absolutely does not do the trick, and I'm at a loss as to why.
_relevant_keys = ["dependencies", "group", "source", "extras"]
def _get_content_hash(pyproject):
content = pyproject["tool"]["poetry"]
print(content)
relevant_content = {}
for key in _relevant_keys:
relevant_content[key] = content.get(key)
print(json.dumps(relevant_content, sort_keys=True).encode())
content_hash = sha256(
json.dumps(relevant_content, sort_keys=True).encode()
).hexdigest()
print(f"Calculated: {content_hash}")
return content_hash
def is_fresh(lockfile, pyproject):
metadata = lockfile.get("metadata", {})
print(f"From file: {lockfile['metadata']['content-hash']}")
if "content-hash" in metadata:
return _get_content_hash(pyproject) == lockfile["metadata"]["content-hash"]
return False
Would love to figure out what exactly the heck I'm missing here - i'm guessing that the poetry locker _local_config gets changed at some point and I've failed to notice it.
References:
Locker: https://github.com/python-poetry/poetry/blob/a1a5bce96d85bdc0fdc60b8abf644615647f969e/poetry/packages/locker.py#L454
core.Factory: https://github.com/python-poetry/poetry-core/blob/afaa6903f654b695d9411fb548ad10630287c19f/poetry/core/factory.py#L24
Naturally, this ended up being a PEBKAC error. I was using the hash generation function from the master branch but using an earlier version of poetry on the command line. Once I used the function from the correct code version, everything was hunky dory.
I think this functionality actually exists in micropipenv now anyways lol
I am not sure if this is the rightest place to ask this but I try anyway. I have to integrate the Python aiortc library in an embedded system which uses Yocto for building the entire environment.
Because there is no recipe for such library, I've generated one using pipoe following this tutorial.
Using the command: pipoe --package aiortc --version 0.9.28 --python python3 I have generated few bb files inside a custom layer such as: python3-aioice_xx.xx.bb, python3-aiortc_xx.xx.bb, python3-cffi_xx.xx.bb and so on (I think those are dependencies).
Now I wanted to compile this recipe to check if everything is sorted with the command: bitbake python3-aiortc, it seems to proceed well and to find all the required files until this error occurs and I don't know how to address it. Can someone help me?
I think that some relevant lines are:
ERROR: python3-aiortc-0.9.28-r0 do_configure: Function failed: do_configure
ERROR: Do not try to fetch `cffi>=1.0.0' for building. Please add its native recipe to DEPENDS.
ERROR: python3-pyee-7.0.1-r0 do_configure: Function failed: do_configure
Have a look to the complete log that I have linked for further info.
===EDIT===
Added the python3-aiortc recipe content.
SUMMARY = "An implementation of WebRTC and ORTC"
HOMEPAGE = "https://github.com/aiortc/aiortc"
AUTHOR = "Jeremy Lainé <jeremy.laine#m4x.org>"
LICENSE = "BSD"
LIC_FILES_CHKSUM = "file://LICENSE;md5=907b5e856b2e6bcd8a3cc8d338a6166f"
SRC_URI = "https://files.pythonhosted.org/packages/1a/34/d9c8e19b4d5157721a5b77750116c6bb6355f1d85b92e7de491269b9ee51/aiortc-0.9.28.tar.gz"
SRC_URI[md5sum] = "50dc651d643b16c95b0e1ad259baeb51"
SRC_URI[sha256sum] = "4a41122e043a75c93a80dbb6d884b6f7cf27b774ebdef226d819a2c3a997c550"
S = "${WORKDIR}/aiortc-0.9.28"
RDEPENDS_${PN} = "python3-aioice python3-av python3-cffi python3-crc32c python3-cryptography python3-pyee python3-pylibsrtp"
inherit setuptools3
Your recipe depends on other recipes. I am guessing you don't have them.
If you have them you probably need to add them to IMAGE_INSTALL_append in local.conf
If you don't have them, you can try to search for them in OpenEmbedded Index, for example:
https://layers.openembedded.org/layerindex/branch/master/recipes/?q=cffi
I am looking at the answer to the following question: Insert Base64 image to pdf using pyfpdf
The answer suggested here was to override the existing load_resource method.
What I did instead was
class EnhancedPdf(FPDF):
def load_resource(self, reason, filename):
if reason == "image":
if filename.startswith("data"):
f = filename.split("base64,")[1]
f = base64.b64decode(f)
f = BytesIO(f)
return f
else:
return super().load_resource(reason, filename)
However, Pycharm highlights the super call with the message "Unresolved attribute reference "load_resource" for class "FPDF"
In my command line, I ran the commands
from fpdf import FPDF
dir(FPDF)
Inspecting this list, I see load_resource function is indeed not a listed method. Hence my question is why is the load_resource function not visible?
Most probably you are using Python 3.x where x >= 5 .
On the pypi it says that the module has only experimental support for python 3.y where y <= 4 .
Try it with python 2.7 and it might work.
PS: Better try https://pypi.org/project/fpdf2/, the updated version. For bugs or issues see https://github.com/alexanderankin/pyfpdf .
If you really want to use the old version, you can install whatever version you want from the original repo like this
pip install git+https://github.com/reingart/pyfpdf#<branchname of tag or commit>
I'm trying to make a simple speech recognition program in Python using Sphinx. I installed it using pip in CMD, then I installed PocketSphinx in the same way. The tutorial I'm following says I need to include the model directories for PocketSphinx, but I don't know where the directory is. How do I find it, and am I doing something wrong?
If you are using pocketsphinx-python installed via pip, and following some example code similar to that provided by the package's github page, you may find there are a few code changes needed.
Here's what's currently in the README (as of March 11, 2018):
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
MODELDIR = "pocketsphinx/model"
DATADIR = "pocketsphinx/test/data"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin'))
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
This not-yet-accepted pull request describes some changes which may help for those of us using pip and working on our python code outside the downloaded module's directory (at least in a *nix/Mac environment, I haven't tested on Windows). Here's a diff snippet; the key idea is to use path.dirname(pocketsphinx.__file__) to get the base directory in which to look for the model directory:
-MODELDIR = "pocketsphinx/model"
-DATADIR = "pocketsphinx/test/data"
+import pocketsphinx;
+POCKETSPHINXDIR = path.dirname(pocketsphinx.__file__)
+MODELDIR = path.join(POCKETSPHINXDIR, "model")
+DATADIR = path.join(POCKETSPHINXDIR, "data")
(Small note: I took liberty to fix a small typo in the spelling of POCKETSPHINXDIR, so this code isn't exactly the same as the pull request)
Go the location where your python is installed look for the following location inside that (this location is according to windows installation)
Lib\site-packages\speech_recognition\pocketsphinx-data
default model is en-US however there are few other language models that one can download from here
https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/
It may be late to answer now, but for newcomers, Python module has some convenience methods:
from pocketsphinx import get_model_path, get_data_path
print(get_model_path())
print(get_data_path())