Seite 1 von 1

import in python venv

Verfasst: Mittwoch 12. April 2023, 14:24
von mallo321123
Hallo, ich bin relativ neu im thema python, ich wollte heute mal eine Bibliothek importieren, aber ich bekomme es nicht hin. also, was ich gemacht habe:
1. einen neuen Projekt Ordner erstellt.
2. eine neue Python installation gemacht mit: python -m venv pfad/zum/ordner
3. mit . fad/zum/ordner/bin/activate aktiviert
4. mit pip install discord.py ein Programm installiert (mir ist da schon aufgefallen, dass er ./lib/python3.10/site-packages als pfad anzeigt, gehört das so?)
5. mit import discord importiert
6. mit VS code ausgeführt
er zeigt mir aber diesen Fehler:
Traceback (most recent call last):
File "/pfad/zur/datei/bot.py", line 3, in <module>
import discord
ModuleNotFoundError: No module named 'discord'

warum ist das so?

Re: import in python venv

Verfasst: Mittwoch 12. April 2023, 16:40
von __blackjack__
@mallo321123: Ist denn für VS code auch dieses venv aktiviert?

Re: import in python venv

Verfasst: Mittwoch 12. April 2023, 20:52
von bwbg
Für jedes neue Terminal-Fenster musst du die venv aktivieren. Diese hat erstmal nichts mit dem Projektverzeichnis zu tun. Du kannst auch mehrere venvs pro Projekt haben.

Re: import in python venv

Verfasst: Donnerstag 13. April 2023, 14:24
von mallo321123
Danke für die Antwort von euch beiden, ich habe eigentlich im VS code im Terminal den venv aktiviert, aber anscheinend hat das nicht direkt funktioniert, ich hab es jetzt gerade noch einmal probiert, jetzt funktioniert alles super, vielleicht hat irgendwas nur mal einen System Neustart Gebraucht. Aber Danke an euch beide für die Antwort!!