[MAC] Python verhunzt

Probleme bei der Installation?
Antworten
seyjo
User
Beiträge: 6
Registriert: Donnerstag 25. März 2021, 04:28

Hallo,

ich habe auf meinem Desktop PC Python uns spiel damit gerne mal etwas rum.

Habe vor 2 Monaten einen neuen Kurs angefangen und damals mich rumgequält mit den Python Versionen.
Hatte einen Haufen Python Versionen auf dem Mac und es irgendwie geschafft alle bis auf die Standard 2.7 zu löschen.

Daraufhin hatte ich die Version 3.10.2 installiert.

Darüberhinaus konnte ich ein virtialinviroment erstellen und auf dem Editor Atom den auch so einstellen dass ich darauf Zugang habe.

Soweit schön und Gut.

Heute, zwei Monate später:
Ich habe wieder etwas Zeit und wollte den Kurs anfangen.
Ich müsste pandas installieren aber bekomme es beim Besten Willen nicht hin.

In Atom bekomme ich folgende Meldung

Code: Alles auswählen

File "/Users/stelio/venv/FCCML/Ohne Titel.py", line 1
    pip install pandas
        ^^^^^^^
SyntaxError: invalid syntax
Also dachte ich, ich mach das über das Terminal.

Das Ding ist, ich habe keine Ahnung mehr wie ich ins „Vene“ Environment komme.

Hab gegoogelt, alles was ich fand ging nicht.

Anschließend dachte ich, ich muss auf python3 pip neu installieren, da das Terminal auf nix reagiert hat.

Bin ich im „python3“ „ordner?“ im Terminal, kommt sowohl bei
sudo easy_install pip
als auch
easy_install pip

folgende Meldung:

Code: Alles auswählen

File "<stdin>", line 1
    sudo easy_install pip
gebe ich im Terminal ohne zu python zu wechseln die Sachen ein kommt eine Fehlermeldung:

Code: Alles auswählen

Searching for pip
Reading https://pypi.org/simple/pip/
Downloading https://files.pythonhosted.org/packages/99/bb/696e256f4f445809f25efd4e4ce42ff99664dc089cafa1e097d5fec7fc33/pip-22.1.tar.gz#sha256=2debf847016cfe643fa1512e2d781d3ca9e5c878ba0652583842d50cc2bcc605
Best match: pip 22.1
Processing pip-22.1.tar.gz
Writing /tmp/easy_install-vhc1_3/pip-22.1/setup.cfg
Running pip-22.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vhc1_3/pip-22.1/egg-dist-tmp-MWvrhq
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 13, in <module>
    load_entry_point('setuptools==41.0.1', 'console_scripts', 'easy_install')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 2316, in main
    **kw
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 418, in run
    self.easy_install(spec, not self.no_deps)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 679, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 705, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 890, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1158, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1144, in run_setup
    run_setup(setup_script, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 253, in run_setup
    raise
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 250, in run_setup
    _execfile(setup_script, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 44, in _execfile
    code = compile(script, filename, 'exec')
  File "/tmp/easy_install-vhc1_3/pip-22.1/setup.py", line 7
    def read(rel_path: str) -> str:
                     ^
SyntaxError: invalid syntax
die easy install Variante wirft folgendes raus:

Code: Alles auswählen

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-18190.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://setuptools.readthedocs.io/en/latest/easy_install.html

Please make the appropriate changes for your system and try again.
installieren irgendwelcher packages kann ich auch nicht, da pip fehlt.



Zugang zu irgendwas hab ich auch nicht, wirft mir direkt eine Error Meldung.

Ich hab also Python auf dem Macbook dass ich nur für ein print(„hello world“) nutzen kann.



Wie bekomme ich meinen Mac wieder sauber, rafft einfach nicht und weiß auch im besten Willen nicht mehr wie ich das virtuelle Environment von vor zwei Monaten installiert bekommen hab...

Vielen Dank schonmal

Grüße

Stelio
Benutzeravatar
pillmuncher
User
Beiträge: 1484
Registriert: Samstag 21. März 2009, 22:59
Wohnort: Pfaffenwinkel

seyjo hat geschrieben: Mittwoch 11. Mai 2022, 23:34

Code: Alles auswählen

File "/Users/stelio/venv/FCCML/Ohne Titel.py", line 1
    pip install pandas
        ^^^^^^^
SyntaxError: invalid syntax
Du versuchst hier einen Shell-Befehl als Python auszuführen. Shell-Befehle sind kein Python, sondern Shell-Befehle. Die musst du in einer Shell ausführen, zB. bash, zsh oder fish. Diese Shells laufen in einem Terminalemulator, oder kurz: Terminal.
seyjo hat geschrieben: Mittwoch 11. Mai 2022, 23:34

Code: Alles auswählen

...
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 44, in _execfile
    code = compile(script, filename, 'exec')
  File "/tmp/easy_install-vhc1_3/pip-22.1/setup.py", line 7
    def read(rel_path: str) -> str:
                     ^
SyntaxError: invalid syntax
Du versuchst hier, in Python2.7 Type Annotations zu verwenden, die aber erst in Python3.5 eingeführt wurden. Python2 solltest du überhaupt nicht mehr verwenden, da es seit über zwei Jahren nicht mehr maintained wird, also weder Bug Fixes noch Sicherheitsupdates bekommt.
seyjo hat geschrieben: Mittwoch 11. Mai 2022, 23:34

Code: Alles auswählen

error: can't create or remove files in install directory
...
Perhaps your account does not have write access to this directory?
Hast du denn Schreibrechte für das Verzeichnis? Im Übrigen sieht es nicht so aus, als würdest du ein venv verwenden, sondern das Python, das dein System verwendet. Falls du tatsächlich eine virtuelles Environment angelegt hast, musst du es aktivieren, indem du in der Shell in dein Projekt-Verzeichnis wechselst - mit cd - und dort activate aufrufst. Oder du legst gleich eine neues venv an. Installiere dazu die gewünschte Python-Version auf deinem Rechner (zB. 3.10) und verwende diese zum Anlegen des venv:

Code: Alles auswählen

$ <da wo du das Python installiert hast>/bin/python3 -m venv <da wo dein Projekt leben soll>
In specifications, Murphy's Law supersedes Ohm's.
seyjo
User
Beiträge: 6
Registriert: Donnerstag 25. März 2021, 04:28

Danke dir für deine Antworten.

Also, hab das venv gefunden und konnte es auch aktivieren (wie es scheint)
Doch irgendwie ist da noch immer krumm.
Hab mir die Order angesehen, da sind pip datein drin, will ich jedoch was über den pip Befehl installieren kommt das.

Code: Alles auswählen

-bash: /Users/stelio/venv/bin/pip: /Users/stelio/venv/bin/python3: bad interpreter: No such file or directory
aktiviere ich über "python3" python bekomme ich syntax errors wegen dem pip Befehl.

Will ich pip installieren geht das nicht da 2.7 aktiviert ist, Wechsel ich auf python3, gibts den syntax Error wie oben beschrieben.

Neu aufsetzen geht auch nicht:
Hab einen neuen Order erstellt,
cd venv2
virtualenv venv

kommt:

Code: Alles auswählen

python3.10: posix_spawn: /usr/local/Cellar/python@3.10/3.10.1/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python: Undefined error: 0
virtualenv kann ich ja auch nicht neu installieren da sich nirgends die pip installation ausführen lässt.

Wenn ich im neuen venv2 pip installieren möchte:

Code: Alles auswählen

Searching for pip
Reading https://pypi.org/simple/pip/
Downloading https://files.pythonhosted.org/packages/99/bb/696e256f4f445809f25efd4e4ce42ff99664dc089cafa1e097d5fec7fc33/pip-22.1.tar.gz#sha256=2debf847016cfe643fa1512e2d781d3ca9e5c878ba0652583842d50cc2bcc605
Best match: pip 22.1
Processing pip-22.1.tar.gz
Writing /tmp/easy_install-P0A9T7/pip-22.1/setup.cfg
Running pip-22.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-P0A9T7/pip-22.1/egg-dist-tmp-N9z3n4
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 13, in <module>
    load_entry_point('setuptools==41.0.1', 'console_scripts', 'easy_install')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 2316, in main
    **kw
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 418, in run
    self.easy_install(spec, not self.no_deps)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 679, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 705, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 890, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1158, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1144, in run_setup
    run_setup(setup_script, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 253, in run_setup
    raise
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 250, in run_setup
    _execfile(setup_script, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 44, in _execfile
    code = compile(script, filename, 'exec')
  File "/tmp/easy_install-P0A9T7/pip-22.1/setup.py", line 7
    def read(rel_path: str) -> str:
                     ^
SyntaxError: invalid syntax
Stilianoss-MacBook-Pro:venv2 stelio$ python3
Python 3.8.9 (default, Oct 26 2021, 07:25:54) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> sudo easy_install pip
  File "<stdin>", line 1
    sudo easy_install pip
         ^
SyntaxError: invalid syntax

Also standard möchte er es auf 2.7 installieren, was ja nicht geht, Switch ich auf python3 geht überhauptnix...
seyjo
User
Beiträge: 6
Registriert: Donnerstag 25. März 2021, 04:28

Also ich verstehe es echt nicht ganz.

Hab Homebrew installiert.
Mit brew install python python neu geladen, lief auch durch.

geb ich ein python --version kommt Version 2.7
Geb ich python3 ins Terminal ein und erfrage dann die Version:

Code: Alles auswählen

Stilianoss-MBP:~ stelio$ python3
Python 3.9.12 (main, Mar 26 2022, 15:52:10) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python --version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>> 
suche ich nach allen existierenden Versionen auf dem System, kommt dass:

Code: Alles auswählen

stelio$ ls -l /usr/bin/python*
lrwxr-xr-x  1 root  wheel      75  1 Jan  2020 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel      82  1 Jan  2020 /usr/bin/python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x  1 root  wheel      75  1 Jan  2020 /usr/bin/python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel      75  1 Jan  2020 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel      82  1 Jan  2020 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  1 root  wheel  137616  1 Jan  2020 /usr/bin/python3
lrwxr-xr-x  1 root  wheel      76  1 Jan  2020 /usr/bin/pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x  1 root  wheel      76  1 Jan  2020 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
was hab ich denn da installiert über homebrew installiert?

Ich checks nicht.
Schaut man sich die Liste oben an, ist der python3 part recht leer, warum bekomme ich trotzdem teilweise infos dass ich 3.9 oder 3.10 installiert habe wenn das nicht da ist??

Das ganze system scheint mir ist komplett durcheinander
seyjo
User
Beiträge: 6
Registriert: Donnerstag 25. März 2021, 04:28

Ok, bin etwas weiter gekommen

Homebrew scheint das system zu spiegeln oder so.
mit

Code: Alles auswählen

export PATH="/usr/local/opt/python/libexec/bin:$PATH"
konnte ich das "überschreiben" vorher hat python --version die 2.7er version ausgespuckt, python3 --version dann die 3.9er.

Nach dem Befehl oben ist es korrekt und ich kann auch endlich nach 2 Abenden pandas ins venv2 installieren.

Mir hat die Seite hier geholfen:
https://docs.python-guide.org/starting/install3/osx/

Das Problem nun, starte ich das Terminal neu ist wieder die alte Version drin.

Über Atom hab ich nun auch nur die alte 2.7er Version drin.

Wie bekomme ich die python3 version als Hauptversion?
Benutzeravatar
snafu
User
Beiträge: 6736
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

Ich kann jetzt nur für Debian-basierte Systeme sprechen, ist aber vielleicht auf dein System übertragbar. Da gibt es pip3 zum Installieren von Paketen unter Python 3. Außerdem lässt sich das Paket python-is-python3 installieren. Dann macht man weiterhin alles mit den Befehlen python bzw pip, aber ausgeführt wird die jeweilige 3er Version. Das kann man aber auch manuell erreichen, indem man den entsprechenden Symlink setzt - oder wie gesagt ans Kommando hintendran die 3 anfügt.
Antworten