1
50
2
11

I can't get my program to use pandoc from inside a venv.

I can use pandoc from the system context.

From inside the venv

which pandoc
/usr/bin/pandoc 

I've installed pandoc inside the venv with pip, and confirmed the files are in the venv.

What am I missing?

3
24

It isn't anything particularly amazing but I'm proud of it! Code can be found here: https://github.com/ArmoredThirteen/PysidianSiteMaker

The general use case is that I'm making a setting and I store all my notes in an Obsidian project. It used to be when I shared notes it was a giant pain trying to send people files so I decided to set up a website. I was using a tool called ObsidianHTML but it doesn't get updated very often and I've had to do some questionable downgrades on my build server to keep using it. It's also way more advanced than what I have use for and I get lost in the aging documentation

So now I'm building a replacement command line tool! My build server picks up on changes made to the settings repo, pulls them in and my PSM code, converts the vault to an html website, and deploys from there. Bonus points is that since my tool is so dedicated purpose the build times have been cut so I can deploy faster than ever

I've never made anything like this before and I'm admittedly not great at Python, I've spent most my time in C#. I know there are lots of areas that aren't written the best and I'm sure there's plenty I don't know about too, despite the small size. I'm always up for feedback!

4
8

Hello, Python Community!

Has someone been able to successfully connect to an IBM Informix DB with a Python app? I have the following environment: DEV: Windows 11 Python 3.13.3 64-bit VS Code

DB: IBM Informix 12.10 hosted in Azure I'm able to connect to it usind DBeaver (JDBC)

I have tried the following libraries to try to establish the connection: ibm_db: Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\ibm_db_test.py", line 1, in <module> import ibm_db as db ImportError: DLL load failed while importing ibm_db: The specified module could not be found._

pyodbc: I have an ODBC DSN connection established Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\pyodbc_test.py", line 3, in <module> conn = db.connect("Dsn='DSN_NAME'") pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

JayDeBeAPI: I have downloaded the same JAR files as DBeaver uses and copied them to a dir local to the project and added the CLASSPATH variable: set "CLASSPATH=%PROJECT_ROOT%\Java\jbc-4.50.10.1.jar:%PROJECT_ROOT%\Java\bson-3.8.0.jar"

File "c:\Users\peterg\source\python\dbApp\JayDeBeApi_test.py", line 3, in <module> dbConn = db.connect("com.informix.jdbc.IfxDriver", "jdbc:informix-sqli://hostname:port/db_name:INFORMIXSERVER=server_name", ['user', 'pass']) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype jpype.JClass(jclassname) ~~~~~~~~~~~~^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jpype\_jclass.py", line 99, in __new__ return _jpype._getClass(jc) ~~~~~~~~~~~~~~~~^^^^ TypeError: Class com.informix.jdbc.IfxDriver is not found

PyInformix: SADeprecationWarning: The dbapi() classmethod on dialect classes has been renamed to import_dbapi(). Implement an import_dbapi() classmethod directly on class <class 'pyinformix.ifx_jdbc.InformixJDBCDialect'> to remove this warning; the old .dbapi() classmethod may be maintained for backwards compatibility. engine = create_engine('informix+ifx_jdbc://hostname:port/db_name;INFORMIXSERVER=server_name;delimident=y;user=user;password=pass') Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\PyInformix_test.py", line 5, in <module> conn = engine.connect() File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 3274, in connect return self._connection_cls(self) ~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 146, in __init__ self._dbapi_connection = engine.raw_connection() ~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 3298, in raw_connection return self.pool.connect() ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 449, in connect return _ConnectionFairy._checkout(self) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 1264, in _checkout fairy = _ConnectionRecord.checkout(pool) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 713, in checkout rec = pool._do_get() File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\impl.py", line 179, in _do_get with util.safe_reraise(): ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__ raise exc_value.with_traceback(exc_tb) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\impl.py", line 177, in _do_get return self._create_connection() ~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 390, in _create_connection return _ConnectionRecord(self) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 675, in __init__ self.__connect() ~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 901, in __connect with util.safe_reraise(): ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__ raise exc_value.with_traceback(exc_tb) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 897, in __connect self.dbapi_connection = connection = pool._invoke_creator(self) ~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\create.py", line 646, in connect return dialect.connect(*cargs, **cparams) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\default.py", line 625, in connect return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501 ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype jpype.JClass(jclassname) ~~~~~~~~~~~~^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jpype\_jclass.py", line 99, in __new__ return _jpype._getClass(jc) ~~~~~~~~~~~~~~~~^^^^ TypeError: Class com.informix.jdbc.IfxDriver is not found

IfxPy:

Uanble to install, seems that it does not support the latest Python 3 version.

Any help would be appreciated. I can attach the sample code of every method I tried if that would help.

5
14
submitted 1 week ago by neme@lemm.ee to c/python@programming.dev
6
116
7
9
Pytorch internals (blog.ezyang.com)
8
24

Was going through a Python tutorial, but it seems kinda dated. Wanted to know if people regularly use docstrings in the workforce. Or are they somewhat irrelevant because you can convey most of that info via comments and context? Do jobs make you use them?

9
38
submitted 1 week ago by neme@lemm.ee to c/python@programming.dev
10
16
submitted 1 week ago* (last edited 1 week ago) by ArmoredThirteen@lemmy.zip to c/python@programming.dev

Hello if anyone knows of a way to get python-markdown to behave in the way I'd like, or of an alternative way to do it, I'd love some help! My use case is I'm converting .md files made with Obsidian into html files. Obsidian has tags that are a pound sign followed by the tag (so like "#TagName"). When the tag is the first item on a line the pound sign is confused for a heading, even though there is no space after it.

Is there a way that I can avoid this so it only reads it as a heading if there is a space between the pound and the next word? I'm even considering some kind of find/replace logic so I can swap it out with like a link to a page that lists all the pages with that tag or something that gets run before the markdown to html conversion.

Edit: The solution I'm going for is a regex find/replace. Currently the string pattern looks like "#[^\s#][^\s" + string.punctuation + "#]*" which can find tags but ignores headers. Since the ultimate goal is to have the tags link to a tag page anyway I can solve it all in one step by doing a replace with a relevant link.

11
11
submitted 2 weeks ago* (last edited 2 weeks ago) by thickertoofan@lemm.ee to c/python@programming.dev

cross-posted from: https://lemm.ee/post/59714239

Some custom filter kernel to average out values from a chunk of pixels with some kind of "border aware" behaviour?

12
9
submitted 2 weeks ago* (last edited 2 weeks ago) by zkfcfbzr@lemmy.world to c/python@programming.dev

I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect.

I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way that's both consistent and inconsistent.

The simplest possible case I found that reproduces the error is this script:

import time
from pynput import keyboard

# Sleep statement is just to give time to move the mouse cursor to a text input field
time.sleep(2)

my_kb = keyboard.Controller()

text = 'πŸ†' # Eggplant emoji
my_kb.type(text)

time.sleep(1)

text = 'π•₯𝕖𝕀π•₯' # blackboard bold test
my_kb.type(text)

time.sleep(1)

text = '𝐭𝐞𝐬𝐭' # bold test
my_kb.type(text)

When I run that script right now, it produces the output "πŸ†π•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭". And if I run it again, it'll produce the same output. And if I change the eggplant emoji to something else, like the regular character 'A', it will still produce the same output (specifically "Aπ•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭"). But... If I log out and log back in, then the output changes to something else that's still wrong, but differently. For example, when I changed the eggplant to a regular 'A', then relogged, the output became "Aπ•₯𝕖𝕖π•₯𝐭𝐞𝐞𝐭". And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings don't change, then the incorrect outputs don't change on relog - but if they do, then they do.

In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get "πŸ†π•–π•€πŸ†". This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions.

I am very new to Linux. I'm on Linux Mint. I'm running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.

13
9
14
10
15
28
submitted 3 weeks ago* (last edited 3 weeks ago) by AstroLightz@lemmy.world to c/python@programming.dev

I made this Python menu-driven CLI script for yt-dlp. It guides you through a series of menus to download content from a YouTube URL.

If anyone is interested, feedback would be greatly appreciated as only I have tested this so far, and I want to make sure it works for other people's systems.

If you encounter any issues or bugs, let me know so I can fix them!

Edit: I should mention: This is not a pipx package. That was never the intention developing this initially. I might make it a package in the future, but for now, it is just a project directory.

16
7
17
19
submitted 1 month ago* (last edited 1 month ago) by milon@lemm.ee to c/python@programming.dev

if coin == 25 | 10 | 5:

If I replace the '|' with 'or' the code runs just fine. I'm not sure why I can't use '|' in the same statement.

Doing the following doesn't work either:

if coin == 25 | coin == 10 | coin == 5:

I know bitwise operators can only be used with integers, but other then that is there another difference from logical operators?

18
18
19
-12

Why is learning Python a mistake for beginners? https://chat-to.dev/post?id=QWV6WTNiZ2hoZlp5S3lFcklZRWcwdz09&redirect=/profile?u=amargo85 #python #programming #code #developers #softwaredevelopment

20
24
Find the bug (a classic) (programming.dev)
class Node:
    def __init__(self, edges = set()):
        self.edges = edges


def main():
    foo = Node()
    bar = Node()
    quz = Node()

    foo.edges.add(bar)
    bar.edges.add(foo)

    assert(foo is not bar) # assertion succeeds
    assert(foo is not quz) # assertion succeeds
    assert(bar is not quz) # assertion succeeds
    assert(len(quz.edges) == 0) # assertion fails??


main()

spoilerMutable default values are shared across objects. The set in this case.

21
15
22
15
Profiling slow imports in Python (jackevans.bearblog.dev)
23
12

My personal experience writing a multi-platform desktop app (macOS, Windows, Linux) was rather painful. Tkinter was my first try, but deployment on macOS was a nightmare. I ended using PySide, which ticked all the boxes, but my biggest gripe is that you end with a lot of code that is not very "pythonic". Flet looks like a nice alternative.

24
4
submitted 1 month ago* (last edited 1 month ago) by logging_strict@programming.dev to c/python@programming.dev

Market research

This post is only about dependency management, not package management, not build backends.

You know about these:

  • uv

  • poetry

  • pipenv

You are probably not familiar with:

  • pip-compile-multi

    (toposort, pip-tools)

You are defintely unfamiliar with:

  • wreck

    (pip-tools, pip-requirements-parser)

pip-compile-multi creates lock files. Has no concept of unlock files.

wreck produces both lock and unlock files. venv aware.

Both sync dependencies across requirement files

Both act only upon requirements files, not venv(s)

Up to speed with wreck

You are familiar with .in and .txt requirements files.

.txt is split out into .lock and .unlock. The later is for packages which are not apps.

Create .in files that are interlinked with -r and -c. No editable builds. No urls.

(If this is a deal breaker feel free to submit a PR)

pins files

pins-*.in are for common constraints. The huge advantage here is to document why?

Without the documentation even the devs has no idea whether or not the constraint is still required.

pins-*.in file are split up to tackle one issue. The beauty is the issue must be documented with enough details to bring yourself up to speed.

Explain the origin of the issue in terms a 6 year old can understand.

Configuration

python -m pip install wreck

This is logging-strict pyproject.toml


[tool.wreck]
create_pins_unlock = false

[[tool.wreck.venvs]]
venv_base_path = '.venv'
reqs = [
    'requirements/dev',
    'requirements/kit',
    'requirements/pip',
    'requirements/pip-tools',
    'requirements/prod',
    'requirements/manage',
    'requirements/mypy',
    'requirements/tox',
]

[[tool.wreck.venvs]]
venv_base_path = '.doc/.venv'
reqs = [
    'docs/requirements',
]

dynamic = [
    "optional-dependencies",
    "dependencies",
    "version",
]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements/prod.unlock"] }
optional-dependencies.pip = { file = ["requirements/pip.lock"] }
optional-dependencies.pip_tools = { file = ["requirements/pip-tools.lock"] }
optional-dependencies.dev = { file = ["requirements/dev.lock"] }
optional-dependencies.manage = { file = ["requirements/manage.lock"] }
optional-dependencies.docs = { file = ["docs/requirements.lock"] }
version = {attr = "logging_strict._version.__version__"}

Look how short and simple that is.

The only thing you have to unlearn is being so timid.

More venvs. More constraints and requirements complexity.

Do it

mkdir -p .venv || :;
pyenv version > .venv/python-version
python -m venv .venv

mkdir -p .doc || :;
echo "3.10.14" > .doc/python-version
cd .doc && python -m venv .venv; cd - &>/dev/null

. .venv/bin/activate
# python -m pip install wreck
reqs fix --venv-relpath='.venv'

There will be no avoidable resolution conflicts.

Preferable to do this within tox-reqs.ini

Details

TOML file format expects paths to be single quoted. The paths are relative without the last file suffix.

If pyproject.toml not in the cwd, --path='path to pyproject.toml'

create_pins_unlock = false tells wreck to not produce .unlock files for pins-*.in files.

DANGER

This is not for a faint of heart. If you can avoid it. This is for the folks who often say, Oh really, hold my beer!

For pins that span venv, add the file suffix .shared

e.g. pins-typing.shared.in

wreck deals with one venv at a time. Files that span venv have to be dealt with manually and carefully.

Issues

  1. no support for editable builds

  2. no url support

  3. no hashs

  4. your eyes will tire and brains will splatter on the wall, from all the eye rolling after sifting thru endless posts on uv and poetry and none about pip-compile-multi or wreck

  5. Some folks love having all dependency managed within pyproject.toml These folks are deranged and its impossible to convince them otherwise. pyproject.toml is a config file, not a database. It should be read only.

  6. a docs link on pypi.org is 404. Luckily there are two docs links. Should really just fix that, but it's left like that to see if anyone notices. No one did.

25
45
view more: next β€Ί

Python

6998 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS