Python help - modules

Hello Fam,

Touching Python for the first time in about a year. Working in Ubuntu.

Having an issue installing, locating, using modules. Previously when working in Python, I could have sworn if there was a missing module imported it would download automatically. I could be wrong.

Nonetheless, trying to install a module via pip3 and I get a syntax error.

wwed@wwed-Z590-AORUS-MASTER:~$ /bin/python3 "/home/wwed/pip install pandas.py"
  File "/home/wwed/pip install pandas.py", line 1
    pip3 install pandas
         ^^^^^^^
SyntaxError: invalid syntax

Can someone help me on this?

I do python3 -m pip install pandas

edit
Although I just tried from the terminal pip3 install pandas and it was working for me. . . Reviewing your code not sure why you called python and then a path to pip?

:~$ /bin/python3 "/home/wwed/pip install pandas.py"

Thanks for the follow-up,

I get this funky output

wwed@wwed-Z590-AORUS-MASTER:~$ python3 -m pip install pandas
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Because I have no idea what I’m doing :rofl:

1 Like

I’m on Fedora, and definitely do not get messages like that. Maybe I should have said that earlier, Try your original command pip3 install pandas .

Creating a venv is a good way to go if yu want to isolate your packages for a project, keeping them away from system packages for clutter.

I created a venv, how do I go about insuring i use the venv as opposed to it using whatever it is defaulting to?

using the original pip3 install pandas is what yielded the message.

Usually it’s tied with your python. Ubuntu iirc has a system python.

When you setup an environment venv and conda, you have to activate your environment, then while in the environment you can use pip install package

I use miniconda and conda environments for my day to day. When I install packages I run

Conda activate my-environment
Pip install pandas

Thats interesting and it worked although I’ve never or never recall using venv before. I wonder if I adulterated by system by installing multiple versions.

Probably, but environments should separate it and make it so that you don’t have to specify which python and the pip package location. What likely happened is you ran pip3 install pandas so it tried using the system’s python

Also you don’t need pandas.py. Pip is a python package manager similar to apt. You don’t need to include the file extension

Thanks,

If I could, I would like to be able to blow python away and start from scratch to keep it clean

Yeah just don’t uninstall your system’s python distribution

You should be able to see you python info using which python

lol too late

WWED
^^^^ is idiot

Might have to open a new thread

Probably better to keep it on this thread

If you’re writing Python, Poetry is a nice dependency manager https://python-poetry.org/.

1 Like

wwed@wwed-Z590-AORUS-MASTER:~$ sudo python3.12 -m easy_install pip
sudo: python3.12: command not found
wwed@wwed-Z590-AORUS-MASTER:~$ sudo python3.8 -m easy_install pip
sudo: python3.8: command not found
wwed@wwed-Z590-AORUS-MASTER:~$ sudo python3 -m easy_install pip
/usr/bin/python3: No module named easy_install

I am starting to remember now that in my old projects it was just getting to be able to work in python was the long part and scripting was the easy part

1 Like

Hmmm
How about

Was linked in the answer

If you don’t mind IDE’s, consider PyCharm or VSCodium. They have some dependency management type stuff built in, including installing and managing python for you.

This is PyCharm’s built in terminal:
Screenshot_20240106_191137

1 Like