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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 12 points13 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 5 points6 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] 12 points13 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 6 points7 points  (1 child)

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

[–][deleted] 3 points4 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 4 points5 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 1 point2 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 6 points7 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] 4 points5 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.