#๐Ÿ”’ How do I install Python and other Python libraries/tools locally to my computer?

51 messages ยท Page 1 of 1 (latest)

lament glacier
#

I've recently begun the CS50P course and their web-based codespace doesn't seem to be meant for importing other tools like matplotlib into the system. I've managed to install Python locally to my computer, but I couldn't get it to work with matplotlib and other related tools that involve graphing/data analysis. Any recommendations and/or resources?

Note - I'm a complete beginner to programming.

cloud knotBOT
#

@lament glacier

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

icy spruce
#

what does "couldn't get it to work" mean?

#

What did you do, what did you observe in response, how did that differ from what you expected?

sudden shale
#

!doc pip

Note that matplotlib et al are third party packages you need to install using pip after you have Python itself.

cloud knotBOT
#
pip

%pip```
Run the pip package manager within the current kernel.
sudden shale
#

It depends a bit on your work environment/IDE. VSCode, Jupyter, PyCharm?

#

... or something else.

lament glacier
#

Right now I'm using CS50P's provided, web-based (on Google Chrome browser) codespace/github (I think). I'm running the code as shown above, not receiving error messages, but the plot still doesn't show in the terminal. I'm trying to install Python separately now, locally to my computer, while also being able to integrate third-party packages like matplotlib, but I haven't found much success or have found anything online that helped. I've downloaded the latest version of Python and have not gone any farther from there. What should I do next?

sudden shale
#

In your codespace thing, maybe a final show() to show the plot? ax.plot() just draws stuff on the plot. So you need:

from matplotlib.plotly import show
... generate the plot ...
show()
#

A common practice is to:

from matplotlib import plotly as plt

and then just invoke plt.show() or plt.subplots(......) etc as needed instead of imports individual names directory from matplotlib.plotly.

#

@lament glacier ^^

lament glacier
#

Hm I tried those and the codespace terminal just goes blank, it doesn't execute anything.

#

Is there an easier way to do this? I don't want to rely on this CS50P web-based workspace because they restrict some things I might not know about hence the confusion

viral steppe
#

Because this is specific to CS50P, I find they have some instructions for working in VS Code locally.
The big part being they have a devcontainer.json config with quite a lot of tooling defined there, so you can get started more easily.
See: https://cs50.readthedocs.io/cs50.dev/#offline-with-docker

#

Yes you can install things on your local machine without Docker, but you may want to stick to the course tooling for now to avoid these headaches and stay focused on the learning materials.

lament glacier
crude leaf
lament glacier
viral steppe
#

Which is what codespaces are, anyway

#

A workaround from that SO post is to make a .ipynb file, which is a notebook. Might be able to render the plots natively that way

#

(with that, pardon, I have to run)

crude leaf
lament glacier
#

Ah, thanks guys, that helps. Last thing: where can I make that .ipynb file and where do I implement the above code?

sudden shale
lament glacier
sudden shale
#

I see you're running IDLE. How did you invoke that?

#

@lament glacier I assume that came with the python instal. So get yourself a windows command prompt (eg PowerShell). Type:

py -m pip install numpy

See what that does.

lament glacier
lament glacier
#

If not the Python install, what is the normal way to get Python locally installed onto the computer, and if not the command prompt, how would I be able to install numpy, matplotlib, and other Python packages?

sudden shale
# lament glacier If not the Python install, what is the normal way to get Python locally installe...

The normal way is either the Microsoft Store (for Windows computers) or an installer from python.org: https://www.python.org/downloads/
I believe you can install multiple versions. The py command you ran runs the default Python, but can be told to run an arbitrary one. Type py -0 to list the various installs.

For now, stick with the one you've got.

To install numpy et al:

py -m pip install matplotlib numpy

or whatever other packages you expect to need.

That installs into the specific Python py would invoke. If you've just got the one you should be good.

lament glacier
#

Oh beautiful

#

Do I need to recurrently update my Python?

sudden shale
#

Not unless you need some shiny new feature.

lament glacier
#

And also is IDLE the normal means to run Python

sudden shale
#

It's a common IDE shipped with Python for writing Python code. There are several choices.

lament glacier
#

When should I transition to VS code (I see that's mainstream amongst programmers)

sudden shale
#

To run a python script you go:

py your-script-filename-here.py
sudden shale
lament glacier
sudden shale
#

Yes, py is run at the command prompt.

#

!resources

cloud knotBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

sudden shale
#

An IDE like VSCode or whatever usually has some "Run" button somewhere.

#

Note that IDEs ("Intergrated Development Environment") are for development. A finished programme won't normally be run from the IDE. If you've written some utility script to do something for you, you'd install (copy) it into a place for your personal commands, and just invoke it by name from the command prompt.

lament glacier
#

Oh okay, thanks so much for all the help

cloud knotBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.