Problem with "pip install"

I use MacOS. However, I cannot use ‘pip’ to install library like the following picture.


Will someone help me solve my problem?

I use MacOS. However, I cannot use ‘pip’ to install library like the following picture.


Will someone help me solve my problem?

The screenshots shows using Python 2.7 but the code expects Formatted String
Literals support, i.e. this:

Try installing your library using pip from python3:

python3 -m pip install gluoncv

What happens?

aaaaaa thank god!!!


The problem puzzling me so long has solved. Thank you very much !!!

However,when I run my code,


it told me that the library “gluoncv” does not exist

Great.

Remember for this project to prefer python3 to python and pip3 to pip.

but when i run my code, they told me there is no ‘gluoncv’, which i dont know why. can u tell me how to solve this?

Are you running using ipython instead of ipython3?

i use spyder in anaconda.

Here too, I’d check if you apt-get installed spyder3 or just spyder.

What is the output of running this inside your Spyder: import sys; print(sys.version_info, sys.executable)?

Ok, as a final attempt, I’d run this and see if as a result of it gluoncv
finally becomes available where you need it:

sudo /opt/anaconda3/bin/python -m pip install gluoncv

Please let me know if in the end we got it! :slight_smile:

For future reference, if you know you are inside conda next time you could
try this style of commands:

https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#installing-packages


It still doesn’t work out. But I have already know how to solve my problem.
However, this platform only allows me sending one picture in a post. I am wondering whether you can tell me your e-mail and I can tell you how I solve this problem.

How did you install or update pip? pip version 21 doesn’t support Python 2 (and you shouldn’t be using it either), but you appear to have pip installed on Python 2.7, which shouldn’t really be possible and could indicate a bug somewhere (albeit possibly in software nobody supports any more)

I now use pip3 to install, with Marco’s advice above. It works well now. Thanks for your concern.

That’s great, but my main concern here is that the error message you got looks like an error that no user should ever get - and if there’s some straightforward explanation for how it happened maybe somebody can make sure nobody else gets the same error in future.

Did you do or try anything to install or upgrade pip before (outside of anaconda)?

Spyder core dev here; we have an official tutorial video and a guide on working with pip, conda, and environments with Spyder. We’re planning several major enhancements to this functionality in Spyder 6, now that Spyder 5 was just released.

From the limited information provided and helping many other users with similar issues with misconfigured environments, while it sounds like you may have temporarily solved the problem for now, your solution may lead to more serious issues with your Anaconda install in the future, either due to an underlying problem (Anaconda/paths/environments not being configured/activated correctly), multiple Python installations and/or mixing pip with conda packages esp. in the base env. I highly suggest you follow the above guide to do things correctly, up to and including re-installing Anaconda and doing things the right way from the start.

In summary, these problems almost invariably come down to one of two things:

  • The Python installation/environment in which you installed the package is not the same as the one you are using within Spyder, or
  • The package was not installed properly (either due to mixing pip/conda/conda-forge or other issues)

To resolve this, please follow the step by step guidance in the second part of the video linked above. In particular, you’ll want to create a new conda environment, activate it and install the package of interest with pip:

conda activate base
conda create -n gluoncv-env python=3.8
conda activate gluoncv-env
pip install gluoncv

If you get an error with the pip install, first confirm pip is actually using the pip in your Anaconda env; pip --version should have anaconda3/envs/gluoncv-env (and certainly gluoncv-env) in the path; otherwise, there is likely a problem activating your Anaconda environment. Try conda init --all, close and re-open terminal and try the last two commands again; if they still don’t work re-install Anaconda.

If gluoncv-env is in the path shown in pip --version but pip outputs an error installing a dependency, try installing them with conda first in a fresh env (it is not recommended to mix pip and conda, but if pip runs into issues it may be the only way to get things working for now):

conda create -n gluoncv-env-conda python=3.8
conda activate gluoncv-env-conda
conda install pillow chardet cycler kiwisolver matplotlib numpy pyparsing python-dateutil requests scipy tqdm urllib3
pip install gluoncv

In any case, once gluoncv is installed, in Spyder, make sure to select this new environment under Preferences > Python Interpreter and start a new console, and import gluoncv should now work.

If things still aren’t working, please post an issue on our issue tracker, @ me (@CAM-Gerlach , same as here) and I can help further, so as not to get off topic here. In particular, make sure to answer all questions in the template and provide full output from the following commands run in your Terminal in the environment where you are attempting to install gluoncv:

  • which -a python
  • python --version
  • python -c "import sys; print(sys.executable); print(sys.version_info)"
  • python -m site
  • python -c "import sysconfig; print(sysconfig.get_paths())"
  • conda info
  • pip info gluoncv
  • conda list gluoncv
  • python -c "for attr in ['file', 'path', 'version']: import PACKAGE; print(getattr(PACKAGE, "__{}__".format(attr), False))""

and the following run in the IPython console in Spyder in the environment in which you attempted to import gluoncv:

  • import sys; print(sys.executable); print(sys.version_info)
  • import sysconfig; print(sysconfig.get_paths())
  • import site; site._script()

Thanks, and best of luck!

3 Likes

Some other observations from the discussion:

I cannot use ‘pip’ to install library like the following picture.

In the first post, your Anaconda env (base) is not properly activated for some reason (otherwise the Anaconda-installed pip should supercede the OS one), and the pip called is the one installed in your macOS system Python (2.7), which should never be used. Furthermore, it seems a Python 3-only version of pip was mistakenly installed into your OS Python somehow (perhaps with python -m pip install --upgrade pip), perhaps because the ancient version of pip bundled with your macOS version didn’t recognize the Python-Requires metadata (which would answer @Maroloccio 's question as to how this is possible, though I’m not certain of this). Naturally, this won’t even run, leaving you permanently unable to install other packages into your OS Python, since pip itself is broken (perhaps not so bad a thing, since this should never be done).

Remember for this project to prefer python3 to python and pip3 to pip […] ipython vs. ipython3 […] spyder vs. spyder3

Most of this was mentioned before you specified you were using Anaconda Python. If your Anaconda environment is activated correctly, python3 and python will both resolve to the Python 3 version bundled with Anaconda (same with pip and pip3), so using versioned Python commands should never be necessary unless something is wrong with your install/config.

Here too, I’d check if you apt-get install ed spyder3 or just spyder […]

The user stated they are running macOS, so these commands would be inapplicable (and, as a sidenote, should use the higher-level apt interface, as apt-get is intended for scripted/advanced use cases). Further, this would install Spyder from the OS package manager, which is not generally recommended as these versions can be very out of date. Instead, the user can (and has) installed Spyder from Anaconda, which is always installed to spyder as the correct version for the current Python runtime (in this case Python 3, as can be seen in the titlebar), and would be installed using conda. Official standalone installers and other install methods are also available.

The problem puzzling me so long has solved. Thank you very much !!!

It is not shown in your highly cropped screenshot which Python install and environment you have managed to install those packages in. The package versions shown are mostly Python 3-only, but if your version of pip was old enough to not handle python-requires, its possible it could be installed in an old Python 2 env. Furthermore, there could be a Python.org or brew Python3 installation that is being used when you execute python3; it is not clear.

What is the output of running this inside your Spyder: import sys; print(sys.version_info, sys.executable) ?

This output looks correct if you’re using the default base env, so I suspect gluoncv was installed in a different Python environment (see previous).

sudo

In general, using sudo to install packages with Anaconda (especially with pip) is likely a very bad idea and means something has gone very wrong with your install, and if not may break things with permissions issues.

For future reference, if you know you are inside conda next time you could
try this style of comman

This is a good idea in general, but as gluoncv is not yet available as a conda package, you’ll need to follow the instructions under installing non-conda packages (as outlined above). Furthermore, some aspects of this guide are out of date (e.g. old activate command, etc; we really should update that).

But I have already know how to solve my problem. […] I now use pip3 to install, with Marco’s advice above. It works well now.

That is good to hear, but it would be very helpful to us and others reading if you could explain how you did so, as is the purpose of these forums. Furthermore, your solution may have broken something else or may break unpredictably in the future, as can often be the case with such things and seems likely given the previous information, so more information may assist in helping us figure out your root problem.

That’s great, but my main concern here is that the error message you got looks like an error that no user should ever get

My guess is that the user ran python -m pip install --upgrade pip with their system Python, which had an ancient enough pip that didn’t recognize python-requires, or the requirement was otherwise ignored. But that’s only a guess.

3 Likes

Further, this would install Spyder from the OS package manager, which is not
generally recommended as these versions can be very out of date.

@CAM-Gerlach : Does Spyder self-upgrade (or remind the user to do so) to ensure
security updates are applied when the software is run outside the OS-managed
package?

Yes; Spyder checks for updates every time it starts, and if one is available, prompts the user to upgrade. The procedure varies depending on the install method (standalone installers, conda, pip, WinPython, MacPorts, distro, source, etc), but the officially supported methods (standalone, conda, pip and source) are always kept up to date with the latest version as soon as its released, and the former two (which are recommended for non-experts) also automatically upgrade all dependencies as well to the latest supported versions. Despite constant outreach to distro maintainers, there is often substantial latency between upstream and distro releases even for critical bugfixes and some have carried long-obselete, unsupported versions for significant stretches of time, and as Conda in particular is very similar in practice to distro packaging systems, I’m not sure I see any plausible security downside from using it.

Also, to note, as a development tool written in pure Python with a fairly small unique attack surface, through Spyder’s over a decade of history and over 15 000 Github issues filed (>90% resolved), there have been very few to no security issues that have been reported with Spyder itself (that are not inherent in its designed purpose, i.e. running arbitrary user-specified code). The only one I can recall that was actively reported over the past few years was being theoretically susceptible, along with a wide variety of other Python programs, to a “badTAR” attack, and as the only vector was Python objects serialized via Python’s pickle protocol, which are already inherently required to be trusted as by design they explicitly invoke arbitrary code execution, there is no additional real-world security impact. In practical, the vast majority of security issues are likely to be found in Spyder’s dependencies, which if Spyder is updated via our recommended methods are automatically kept up to date with Spyder itself.