Spyder Check Installed Packages

5 views
Skip to first unread message

Rosamunda Froats

unread,
Aug 4, 2024, 8:36:25 PM8/4/24
to mezdivobut
Isay "surprisingly", because the package install tool is the exact place one would expect to find this functionality, although not under the name 'freeze', but Python packaging is so weird that I am flabbergasted that this tool makes sense. Pip 0.8.2 and Python 2.7.

Which seems to be syntactic sugar for "pip freeze". It will list all of the modules particular to your installation or virtualenv, along with their version numbers. Unfortunately, it does not display the current version number of any module, nor does it wash your dishes or shine your shoes.


As of pip 10, the accepted answer will no longer work. The development team has removed access to the get_installed_distributions routine. There is an alternate function in the setuptools for doing the same thing. Here is an alternate version that works with pip 10:


!pip list will run inside your jupyter notebook if working there, simplifying the 'quick check'Combine with other utilities like grep(if you have installed)pip list grep pandas will get you your current pandas version for example


A note aside: I've noticed that when I install a packet once via sudo and once without, one takes precedence so that the other one isn't being listed (only one location is shown). I believe that only the one in the local directory is then listed. This could be improved.


What I discovered is that the provided boto3 library was way out of date and it wasn't my fault that my code was failing. I just needed to add boto3 and botocore to my project. But without this I would have been banging my head thinking my code was bad.


Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.


The output from pip list is formatted differently, so if you have some shell script that parses the output (maybe to grab the version number) of freeze and want to change your script to call list, you'll need to change your parsing code.


If you want to get information about your installed python distributions and don't want to use your cmd console or terminal for it, but rather through python code, you can use the following code (tested with python 3.4):


The pip.get_installed_distributions(local_only=True) function-call returns an iterable and because of the for-loop and the print function the elements contained in the iterable are printed out separated by new line characters (\n).The result will (depending on your installed distributions) look something like this:


For Windows 10, I think this is what you are looking for a list of available installed Pythons. This is different from a list of packages as you can see below. Also, on Ubuntu 20.04, I think the command is Python3 -0 list.Yes, this works similar to node version manager.


From the above link, "If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately." -- Note: This acts similar to Node Version Manager with versions of Node.js and NPM.


Action: Open PowerShell and type the following web request. The link above offers other approaches as well, but this appears to be the easiest approach. The name of the runtime output file is not a name variant like 'pyenv-win' but actually 'pyenv', as originally expected.


My Note: Version name from ' ' is different to those provided by 'pyenv'. This version was already installed locally, but it is outside the control of this Python version manager, so it is not visible to the manager.


My Note(s): This Python version is not part of the managed list although this version exists at ' '. So you must see the list provided by the manager. See all available versions with `pyenv install --list'.


My Note(s): With this Python version manager, 'pyenv', following installation, it appears that one must designate the version as 'local' or 'global' after the installation which would follow the same paradigm as the Node.js Version Manager (NVM). Again, from what I can see, the Python version manager can only see what versions of Python the manager installs; and it can only uninstall a version it has installed with the Python version manager.


From the above link, "When the environment is active, any packages can be installed to it via pip as normal. By default, the newly created environment will not include any packages already installed on the machine. As pip itself will not necessarily be installed on the machine. It is recommended to first upgrade pip to the latest version, using 'pip install --upgrade pip'." -- I performed the pip upgrade just before making these two calls to list the packages and their versions below.


While relatively straightforward once you're familiar with it, the interaction between Spyder and other packages and environments can sometimes be confusing for first-time users. Improvements to Spyder have made this process much easier (and there is more to come!), but we'd like to clarify how that relationship works.


We'll start by helping you to debug a common problem encountered in Python when dealing with packages and environments, i.e. when you can't import a module even if you're sure that you've installed it. Next, we'll guide you through setting up your Spyder environment(s) to improve your workflow. If you're looking for a way to use Spyder with different environments (e.g. one for simple data analysis, one for machine learning, one for developing an app, etc.) you can go directly to the final section.


If the resulting paths are the same, then Spyder and the package are in the same environment, and import foo shouldn't produce an error (or else there is likely an unrelated issue with your installation).


Spyder is a Python package just like any other you may be used to, and so you can import any package within its Console or Editor as you could from a regular Python or IPython terminal launched in Spyder's environment:


Therefore, if you'd like to use a package with your existing Spyder install (e.g. importing it into your scripts, packages or a Spyder IPython console), the simplest way to do so is to install the package into the same environment in which you installed Spyder, typically by the same means you installed Spyder (conda, pip, package manager, etc). However, this is not possible if you've used a standalone installer, and if you're installing packages with pip, conda-forge, Github, or custom channels, working on multiple major projects at once, using prebuilt environments, or otherwise have more sophisticated needs, you'll likely want to use one or more separate environments for your packages. If so, the next section explains how.


If you have an existing, pre-configured environment (such as for Keras or TensorFlow), are managing multiple environments (such as for development or testing purposes), or even would like to work within a totally separate Python installation as that in which Spyder is installed (such as a standalone installer Spyder with a separate Anaconda installation, or vice-versa), you can install the modular spyder-kernels package into any Python environment (conda environment, virtualenv/venv, system Python, WinPython, etc) in which you wish to work, and then change the Python interpreter used by Spyder on its IPython consoles to point to the Python executable of that environment.


This takes a small amount of preparation and configuration, but is much "lighter" and quicker than a full Spyder installation into that environment, avoids dependency conflicts, and opens up new workflow possibilities.


Start a new IPython console. All packages installed in your myenv environment should be available there. If conda is used, the name of the current environment and its Python version should be displayed in Spyder's status bar, and hovering over it should display the path of the selected interpreter.


Pip currently ignores uninstall commands that try to uninstall something owned by the OS. It doesn't error out, like it does with a missing package. So, now you can uninstall with the following process:


AFAIK sudo pip install will install on /usr/local/lib/pythonVERSION/dist-packages. You need to run sudo pip uninstall to uninstall packages system wide. It seems that pip freeze looks for package metadata and will list anything installed i.e. both from pip as well as apt-get outside of virtualenvs. There is -l option inside virtual environment to list packages only applicable to that virtual environment but it seems to be default case as well inside virtual environment. I think you can just delete related packages on /usr/local/lib/pythonVERSION/dist-packages as well but not very convenient method I guess.


To determine which Python packages were installed by pip, by the freeze command, which will give you a list of installed packages and their versions. I would suggest removing all instances, and re-installing using the sudo apt-get command


I needed to clean up disk space from Python packages safely. While this is a complete clean out of packages, I needed to move Python versions as well so I did not need old packages. I used the following to get all my package names, skip the first 2 lines and grab the first column, and uninstall without user interaction:


This has something to do with Homebrew. I had no issues with pyodbc on my Mac Air until I installed Homebrew and used it for a few things. I found this thread on github that ends in a solution that worked for me.


Warning: It is highly recommended to install python-modules using official Ubuntu repository only and not to use the pip method as superuser(i.e., as root or using sudo). In some cases it may leave your system unusable by breaking system python.

3a8082e126
Reply all
Reply to author
Forward
0 new messages