Install pypi modules - virtualenv required

I’m trying to install pdfminer thru command line (win10) and the error,

Blockquote

could not find an activated virtualenv

Blockquote
Is creating a venv FOR ANY MODULES you need (that aren’t default python install) a standard practice? I don’t want to use anaconda or pycharm. I just use vanilla python on my windows 10 box.
thanks

Maybe you’ve set a pip option to require virtualenvs? Check with pip config list

aaahhh…

C:\WINDOWS\system32>pip config list
global.require-virtualenv=‘true’
C:\WINDOWS\system32>

So, my question is, is this a standard practice to do? It seems like if you’re doing ANY development this would increase the number of directory’s/projects? Yes?

Generally, we recommend not installing stuff into your system Python because if you do so, then you risk getting problems when two of your programs have conflicting requirements.

So yes, a virtualenv for each project is the typical recommendation. It does take more space, and the learning curve for virtual environments is steeper than just using your system Python, so it’s fine if you choose not to take that route, but generally it’s what works better long-term.

1 Like

Ok. Sounds good @pf_moore.

So, if I’m using python IDLE, how would I import any new/non-standard modules? Would I need to set up an IDLE for EACH venv environment? I’m asking because it seems like VANILLA PYTHON ISN’T THE WAY TO DEVELOP. Maybe, ANACONDA or PyCharm? It seems like they have a better work flow and development flow.

Ok. Sounds good @pf_moore.

So, if I’m using python IDLE, how would I import any new/non-standard
modules? Would I need to set up an IDLE for EACH venv environment?

I expect you’d just need to invoke the IDLE from inside the target
virtual environment. I’m not an IDLE user though.

I’m asking because it seems like VANILLA PYTHON ISN’T THE WAY TO
DEVELOP. Maybe, ANACONDA or PyCharm? It seems like they have a better
work flow and development flow.

@pf_moore’s statement: “Generally, we recommend not installing stuff
into your system Python because if you do so, then you risk getting
problems when two of your programs have conflicting requirements” has
two aspects to it.

First, pip has a --user option to install package in your personal
collection-of-packages (versus installing in the Python install’s area).
IIRC that’s the default these days - it prevents polluting the
system-wide Python install with your personal additions.

Second, development.

For my personal stuff I use plain pip install --user. Or I would
except that I’ve got a few Pythons installed, so in fact I do make a
venv even for my personal use so that I can pick the Python flavour.

For development, a venv is useful because it lets you pick and choose
requirements for the project. This one might want pandas, that one might
want django etc. You generally want to enumerate these so that you can
tell people using your project what they need to install, either
overtly or as metadata.

So I just make a venv at need. It is the work of a moment to make one in
your project’s dev dir and use it as required. Once it’s there, using it
or intalling packages into it is equally easy.

So I’m a “vanilla Python with a venv for dev” person.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

I was going to recommend this previous thread that had a somewhat similar issue and specifically discussion about the virtualenv requirement…when I realized it was you on that thread, which would explain how that option got enabled :joy:

In any case, our advice (e.g. mine) there still applies, so I won’t repeat all that again here. The reason the option is enabled is, presumably, because you followed our recommendation there to turn it on.

To summarize, always installing packages in a venv/conda env is a recommended best practice for both pip and conda. Many Python devs (including me) adheres to it, but it is especially important for newer users, to avoid problems like the one you experienced in your previous issue and make it much easier to recover from them. I believe you’ll find the space and time cost of it to be very small next to what it can save you in terms of having to deal with dependency conflicts, botched installations and other issues. However, you do really want to disable it, you can run the following:

pip config set global.require-virtualenv false

To launch idle, or anything else in the environment, just activate the environment and then start idle from the command line as you usually would do (i.e. python -m idlelib).

1 Like

On Windows, you have to leave [x] install tkinter and IDLE checked to use either. If you do, both are in the stdlib (/Lib) like any other importable module.

import error for me. python -m idlelib should always work.

2 Likes

@CAM-Gerlach ha ha!! I almost fooled you! LOL! Thanks for the help. I just have a hard time having a STANDARD python install, but for every project you do you will need different modules. I think i got it now, but I’ll need to practice some more. Anyways, thanks for your help again.

Ah, thanks for the catch—I should have double-checked, sorry. As I don’t use IDLE myself, I forgot that idlelib is the name stdlib module. Corrected it above, FWIW.

1 Like