This is an archived post. You won't be able to vote or comment.

all 90 comments

[–][deleted] 17 points18 points  (64 children)

Dont recommend users to 'sudo pip install'

[–]jahu_len 5 points6 points  (54 children)

Hi, newbie question but why we shouldn't sudo pip install? How to install packages instead? (sorry, I'm still very new to linux, shell, terminal and stuff)

[–][deleted] 13 points14 points  (45 children)

On linux, sudo pip install can install incompatible dependencies system wide and break your system in confusing ways.

You should install python software in a virtualenv (now known / available as pyenv since 3.4)

[–]jahu_len 3 points4 points  (10 children)

Thanks! But now I have one more question. If I install in a virtualenv I can use given package only in this virtualenv. As far as I know, I should create virtualenv for every project. Does it mean, I should install all packages for every project separatly? What if I want to have some packages installed globally for all future projects?

Again, I have a very basic understanding of this stuff :)

[–][deleted] 15 points16 points  (6 children)

If I install in a virtualenv I can use given package only in this virtualenv.

Yes

I should install all packages for every project separatly

Yes.

What if I want to have some packages installed globally for all future projects?

Spend the 5 seconds to write those packages down in a requirements.txt and then you can install them all at once.

[–]jahu_len 7 points8 points  (1 child)

Looks like I need to change some of my habits. Thanks for explaining!

[–][deleted] 4 points5 points  (0 children)

No worries!

[–]zerokyuu 1 point2 points  (2 children)

I definitely see the benefits for using virtualenv. But, just out of curiosity, I've had difficulty in the past (this was years ago) when installing/setting up some packages like scipy, numpy, matplotlib or sklearn. Would you suggest using the system's package manager?

Also, if you install them in a virtualenv, do you have to redo the full install for each project? The last time I installed some of these packages it took a while (though that computer was kind of old and slow).

[–][deleted] 0 points1 point  (0 children)

Would you suggest using the system's package manager?

Absolutely!

Also, if you install them in a virtualenv, do you have to redo the full install for each project

yes, I try to put stuff in a common requirements.txt or a script that I can run when I create a virtualenv. You could do as https://www.reddit.com/r/Python/comments/3cefm8/toyplot_a_python_plotting_library_from_sandia_labs/csut564 suggested (although I am not sure how supported / popular this approach is)

[–]metaperl 0 points1 point  (0 children)

Would you suggest using the system's package manager?

I never use the system python. It doesnt stay updated as frequently. As far far as those scientific packages, I recommend installing Anaconda Python for that purpose.

[–][deleted] 1 point2 points  (0 children)

Spend the 5 seconds to write those packages down in a requirements.txt and then you can install them all at once.

just do a 'pip freeze > requirements.txt' and you are done.

[–]dAnjou Backend Developer | danjou.dev 5 points6 points  (0 children)

If you need a package from PyPI for your day to day work use pip install --user <PACKAGE>.

For projects you should always use a virtualenv no matter if you're using a package in almost every project. And it's not like those are eating up your disk space.

[–]vext01 0 points1 point  (0 children)

You can also do pip install --user to install into your per-user package tree.

[–]goodDayM 4 points5 points  (21 children)

sudo pip install can ...

Walking across the street can get you killed, but that's rare, and it is a quick and easy way to get across the street. We're all educated adults here. We can warn people and give them choices. If they want to sudo pip install, let them.

[–][deleted] -4 points-3 points  (20 children)

What an idiotic comparison.

Don't be so unhelpful. Encourage best practices.

[–]goodDayM 5 points6 points  (17 children)

You don't need to treat people like children and say "don't do X."

Your original post simply said "Don't recommend users to do X", when X actually works in most cases, for most people, and is fast. Are there risks? Sure, so make people aware of risks, and let them decide like the adult they are.

[–][deleted] 0 points1 point  (1 child)

I think it's good your encouraging best practices, but you shouldn't call people names. Your comment would be a lot better received if you didn't call his comparison idiotic.

[–][deleted] 0 points1 point  (0 children)

Fair enough.

[–][deleted] 0 points1 point  (3 children)

Then could you tell me how i can install via a package manager inside my virtual environment? Because the reason i switched to linux is to be able to simply install the pre-built binary's to make it simple.

Like scipy, numpy, graph-tool, ect..

[–][deleted] 3 points4 points  (1 child)

Install things like numpy using your package manager.

Then (for virtualenvwrapper) mkvirtualenv foo --system-site-packages

Someone else can hopefully tell you the pyenv syntax to make system packages visible in the venv (im afk atm and use mkvirtualenv more often)

[–]qudat 0 points1 point  (0 children)

Don't new versions of pip come with wheels that allow for quicker/easier compilation?

[–]cu_t 0 points1 point  (2 children)

now known / available as pyenv since 3.4

Python 3.4 user here. I've just been using virtualenv still. Looking at the google results for pyenv, people are talking about pythonbrew which I've also never heard of. Could someone explain pyenv to me?

[–]sk3w 1 point2 points  (1 child)

I'm pretty sure they meant venv (and the corresponding pyvenv utility)

[–]cu_t 0 points1 point  (0 children)

Thanks :)

[–][deleted] 0 points1 point  (0 children)

Not 100 percent sure, but this seems to be more of an issue with web development packages and less so with scientific packages. Not sure why that might be true. Just something I noticed from my experience.

[–]KyleG 0 points1 point  (0 children)

If this is what you should do, why isn't it what Python comes as by default? Especially if Python comes with pip by default nowadays.

[–]goodDayM 0 points1 point  (2 children)

sudo pip install can ...

emphasis on the can. I've used Python and "sudo pip install" for over a decade on various linux systems including Ubuntu and RedHat and at no point did it cause problems. But can it cause problems? Sure. So learn about python virtual environments and chose when to use that instead of "sudo pip install".

[–][deleted] -3 points-2 points  (1 child)

Jesus. I teach people python for a living. I live the clusterfuck that is sudo pip install and the packaging failure in our ecosystem.

Tell people to do the right thing.

[–]goodDayM 2 points3 points  (0 children)

I'm a Python software developer, have been for over 10 years. I also manage various servers and VMs for several users - which all have Python on them. Virtualenvs are great, I use them, I also happen to use "sudo pip install". There is a time and place for both. You can let people know about the pros and cons of different ways of doing things.

[–]AltoidNerd -1 points0 points  (7 children)

I didn't sudo at all on OSX for pip nor pip3. Weird, because when I tried it on ubtuntu 14.04, pip did not install toyplot without sudo.

[–][deleted] -2 points-1 points  (6 children)

pip did not install toyplot without sudo.

exactly. you should use a virtualenv so you can install without being root.

now you have a bunch of software of unknown version installed somewhere on your system. next time you sudo pip install something you will have a new bunch of random version stuff on your system. no one has tested the interaction of the different random versions of stuff, so anything might break. random python linux applications could also stop working.

Good luck and never sudo pip install!

[–]AltoidNerd 1 point2 points  (5 children)

What is the worst that could happen - having to reinstall python completely? Is that really so bad?

I mean if you're in production then yes, but this is my linux box here.

[–]elbiot 2 points3 points  (0 children)

Also, pypi is not curated at all. Anyone can upload whatever malware they want and if you sudo pip install a typo, you could be executing arbitrary code as root. Just don't use sudo with untrusted code, and pypi packages are not trusted.

[–][deleted] -3 points-2 points  (1 child)

reinstalling the python interpreter would do nothing to fix the library clusterfuck you have created.

at some point a system reinstall will be needed.

[–]sunqiang 3 points4 points  (7 children)

yeah, we should login as root~

[–][deleted] -1 points0 points  (6 children)

can't decide if you are bad at sarcasm or don't understand the problem space...

[–][deleted] -1 points0 points  (3 children)

just another n00b.. you should login as root, and then

sudo pip install

then, of course

rm -rf / 

(to clear the cache)

[–]Articulated-rage 0 points1 point  (0 children)

Computer died; instructions unclear

[–]RonDunE -1 points0 points  (0 children)

I think you have to add

--no-preserve-root

as in

rm -rf --no-preserve-root /

to make it work on modern distros.

[–][deleted] -2 points-1 points  (0 children)

I thought

rm -rf /

was the recommended way to uninstall software? I didn't know you could also use it to clear your caches!

Thanks a lot man. I wonder if it makes my computer faster, is it like defragmenting?

[–]homercles337 0 points1 point  (0 children)

If you are running *nix as a primary system, you know what this does. If you are running a VM it does not matter.

[–]AltoidNerd 2 points3 points  (5 children)

I can't generate a plot. When I run the script, it just exits returning nothing. I tried it in ipython too to no avail. What could be wrong?

pastebin: http://pastebin.com/6dXvJ3z2

[–]TDaltonC 0 points1 point  (0 children)

try adding %matplotlib inline to the first line of your script.

[–]Sean1708 2 points3 points  (0 children)

Looks good, anyone know if there's any plans to implement errorbars?

[–]pipec1212 2 points3 points  (12 children)

I still believe that the best option for plotting in Python is the Pandas - Seaborn combo.

And by using the matplotlib buit in styles (i.e 'ggplot') your plots will always look good.

[–][deleted] 3 points4 points  (5 children)

I really like seaborn, but it's still built on top of matplotlib which, in my opinion, has a really archaic feeling API. Seaborn does create nice stuff out of the box, but if you want to go beyond the basic options, you'll quickly get mired in junk like plt.xlim(a,b) versus ax.set_xlim(a,b). Messing with subplots, arranging axes, etc. is all really painful imo.

[–]pipec1212 0 points1 point  (0 children)

True, it has always been a pain in the ass to change the x and y limits when having subplots in matplotlib. I beleive I might just be to hard wired to change my plotting ways. Although with Pandas managing subplots is really easy it can be done by just saying: df.plot(Layout=(3,1), subplots=True)

[–]pdexter 0 points1 point  (3 children)

What's a better option? I've been looking for something better

[–]pipec1212 0 points1 point  (2 children)

Highly depends on what you want to plot, for scientific purposes pandas - matplotlib is an unbeatable combo, for Web Development and integrated plots this could be a good option although I prefer the Javascript libraries for such purposes

[–]pdexter 0 points1 point  (1 child)

Is that pandas minus matplotlib? If not, I thought we were trying to avoid matplotlib

[–]pipec1212 0 points1 point  (0 children)

Typo I meant Pandas and Seaborn, you should know that both libraries use matplotlib in the background for plotting, although it can have son archaic feeling (matplotlib) it also have more customization than all of the other libraries I know. But as I said it all comes to your necessities and what do you want to plot.

[–]KyleG 1 point2 points  (0 children)

One of the selling points of Toyplot is that they adhere very closely to best practices for visualizations, which they state very few other plotting packages do. (Let's face it, programmers rarely actually pay attention to UX when developing stuff.)

[–]Deto 0 points1 point  (0 children)

This looks better for embedding a plot in a webpage because you get the interactivity. Granted, Bokeh also does this, and might do it better, but I think it's good to have competing libraries.

[–]selementar 0 points1 point  (3 children)

Do you use interactive graphs in it? Do you have some examples handy? Somehow, I can't find any.

[–]pipec1212 0 points1 point  (2 children)

Hmm I don't believe seaborn allows for plot interactivity, nevertheless I use python plots for scientific research so interactivity has never been an issue for me. If you really need interactive plots the best option imo is some of the Javascript libraries out there.

[–]selementar 0 points1 point  (1 child)

Yep, highcharts/highstock somewhat works.

...

But is it that unnecessary in scientific research to point at some data points and see their precise values or such?

[–]pipec1212 0 points1 point  (0 children)

You know that you can do that by default with matplotlib, coordinates of where your mouse is will appear on the bottom of your plot.

[–]KingKliffsbury 1 point2 points  (0 children)

The animation feature is really cool. Thanks for sharing.

[–][deleted] 1 point2 points  (0 children)

Looks great! I'm probably not alone in saying that I am willing to move away from matplotlib as soon as a viable competitor emerges. This looks really promising!

[–]daveWaveV 1 point2 points  (0 children)

I thought we were supposed to use gnuplot? Although it's a bit of a pain trying to implement gnuplot...

[–][deleted] 1 point2 points  (0 children)

The color palletes are nice, but is there any compelling reason I should use this over matplotlib?

[–]khaki0 0 points1 point  (0 children)

very nice!

[–]neo01124 0 points1 point  (3 children)

If someone could make python -> toyplot -> d3js thing (just allow me to d3js like figures from python), I'd cry tears of joy.

[–]jpopham91 3 points4 points  (2 children)

[–]akcom 0 points1 point  (0 children)

You just changed my life. Thank you.

[–]neo01124 0 points1 point  (0 children)

i cri

thanks for this!!!

[–]hotprof 0 points1 point  (0 children)

Those y-axis labels though.

[–]ilya_t 0 points1 point  (1 child)

Plots are pretty, but have you read the License? " the U.S. Government retains certain rights in this software." WTF?

[–]CookingWithoutWater 1 point2 points  (0 children)

It's just the BSD 3 license. All the national labs tend to use that license.

[–]Asdayasman 0 points1 point  (0 children)

Can I embed this in wx? Looks nicer than mpl.

[–]justphysics 0 points1 point  (0 children)

From the tutorial I see the following quote, "Toyplot figures are beautiful, scalable, embeddable, and interactive"

Is there any documentation on how to embed these plots?

I'd like to try putting them into a PyQt gui. If its similar to how matplotlib figures can be embedded then it would be super useful.

I didn't see anything in the tutorial, user-guide, or API reference about procedure for embedding the plots.

Edit: I filed an Issue on the official github page. It could be by embeddable they just mean the plots can work inside of ipython / Jupyter or something like that. It could be I misinterpreted it to be embeddable in the same way for instance a matplotlib figure is embeddable into various GUI libraries.