can't open dataframe in variable explorer in Spyder IDE - python

Due to Anaconda didn't support free for commercial use. So I downloaded Spyder IDE from Spyder official website.
Spyder official web
Since Spyder IDE doesn't provide a function for users to download libraries as PIP install. But I still love Spyder's UI and some functions, especially, variable explore, etc...
So I installed official python on my PC, taking Spyder IDE as a code editor. <-- It can work by changing the python interpreter in the Spyder preference setting.
But I found an error when I try to open a variable (which is dataframe) on variable explorer, others are work well.
from pandas import DataFrame
People_List = ['Jon','Mark','Maria','Jill','Jack']
df = DataFrame (People_List,columns=['First_Name'])
print (df)

I got the same error and I noticed that I only got it after I created GeoDataFrames from the Geopandas library. Once I restarted Spyder, as long as I don't create a GeoDataFrame, it opens all other DataFrames (from Pandas) just fine.

I had the same issue and setup (windows 10, trying to install and get geopandas to work, but then couldn't get dataframes to be viewed in spyder). Ultimately, running pip install spyder in the new python that I was trying to use in spyder fixed the problem.
However, I think probably switching to an anaconda-based python interpreter in spyder, and installing geopandas and spyder-kernels through conda, would be a better long-term approach. This also has worked for me (I think I have become confused between pip and conda, e.g. this answer re: geopandas asks for pip https://stackoverflow.com/a/58943939/5233269, but conda can also install geopandas -- and most importantly deal with all the dependencies involved. I think conda is probably better long-run for data work.)

Related

If I install anaconda, do I still have to use vscode?

I'm new in programming, actually I use it for Machine Learning.
I have installed python and anaconda (I don't know if that is right, or I have to install only anaconda?).
And I can see in start menu: (Anaconda powershell, Jupyter, Spyder, Anaconda navigator, Anaconda prompt).
So my question is: Do I still have to use vscode as IDE, or one of the listed programs that come with anaconda? If the answer is the second choice, I will ask, which one of them?
Thanks.
I'm using python just because I have a project in ML, So I must to set the necessary things for ML, like libraries, dataset, and algorithms. Then I have to learn how to use them.
Any help will be very apprecheated.
Anaconda is a Python distribution, that not only comes with Python itself, but a lot of additional Python packages from the "scientific stack", like numpy, pandas, matplotlib, scipy, scikit-learn: exactly what you need for ML. You don't have to install anything else from python.org.
Anaconda also comes with the Spyder IDE. This is the perfect choice for a Python beginner. You don't need VSCode. VSCode is way more flexible than Spyder, but you have to get used to it.
Conda is the package manager that comes with Anaconda. Do yourself a favour an learn some conda basics and how to use virtual environments here: https://conda.io/projects/conda/en/latest/user-guide/getting-started.html
The important difference between Anaconda and pure Python is that you have to activate a conda environment - even the "base" environemnt - before you can use it. This is not obvious to a beginner.
If I were you I would use vcscode. Anaconda is only a python with extra features, but to code you would appreciate the VSCOde. It comes with many features and you can install extensions to burst your experience. Go for it.

Spyder standalone environment

I intend to install Spyder standalone on a Mac. (In addition I will use conda to manage my environments, and point Spyder to the environment I want to use.)
Now, suppose I want to manage things in the environment where Spyder itself is installed (the standalone installation), for example install packages there. How do I do it? In a conda environment I could do something like this:
conda activate myenv
and work there. But since Spyder is a standalone environment, how do I access it?
In addition, since this standalone installation goes into "applications" in the mac, will it notify me when a new version of Spyder is available and offer to update (as in other applications?
EDIT:
I found some contradicting-looking information about this. According to this I should probably not install packages there (and maybe it's impossible).
but here
in the first bullet point at the bottom of the page, it says "In order for the Variable Explorer to be able to display the built-in editors for specific data types (Numpy array, Pandas Series/DataFrame, etc) the corresponding optional Spyder dependencies (Numpy, Pandas, etc) need to be installed in Spyder's environment".
(Spyder maintainer here) About your questions:
Now, suppose I want to manage things in the environment where Spyder itself is installed (the standalone installation), for example install packages there. How do I do it?
It's not possible to install any package in our standalone installers. That's by design in order for users to not break them.
If you need to use other packages that don't come with them (e.g. Scikit-learn or Seaborn), you need to create a new environment, install them there and connect Spyder to that environment. That process is better described in these instructions.
since this standalone installation goes into "applications" in the mac, will it notify me when a new version of Spyder is available and offer to update (as in other applications?
We don't offer that functionality yet, but we'll try to do it in the future.
but here in the first bullet point at the bottom of the page, it says "In order for the Variable Explorer to be able to display the built-in editors for specific data types (Numpy array, Pandas Series/DataFrame, etc) the corresponding optional Spyder dependencies (Numpy, Pandas, etc) need to be installed in Spyder's environment".
All optional dependencies needed to explore Numpy arrays and Pandas dataframes are provided in the installers.

IDLE and python is different, not able to install modules properly

thanks for reading this. I am using macOS High Sierra. I am not very familiar with terminal or environment variables, but am trying to learn more. From reading other threads and google, it seems like I either have multiple pythons installed, or have pythons running from different paths. However I am not able to find a solution to resolving this, either by re-pathing my IDLE or deleting it entirely.
I do have python, python launcher, and anaconda (not very sure how anaconda works, have it installed a few years back and didn't touch it) installed. I am trying to install pandas (pip install pandas), which tells me that I have it installed, but when I run it on IDLE, it says module not found. Though if i run python3 on terminal and type my code in, it works (so pandas has indeed been installed).
When i run which python on terminal, it returns
/Users/myname/anaconda3/bin/python
(when i enter into this directory from terminal, it shows that in the bin folder, I have python, python.app, python3, python3-config, python3.7, python3.7-config, python3.7m, python3.7m-config)
When i run which idle on terminal, it returns
/usr/bin/idle (im not even sure how to find this directory from the terminal)
When i run import os; print(os.path) on IDLE, it returns module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py'
Would really appreciate some help to figure out how to ensure that when i install modules from terminal, it would be installed into the same python as the one IDLE is using. Also, I would like to know whether it is possible for me to work on VSCode instead of IDLE. I cant seem to find suitable extensions for data science and its related modules (like statsmodels, pandas etc). Thanks a lot!
First of all, a quick description of anaconda:
Anaconda is meant to help you manage multiple python "environments", each one potentially having its own python version and installed packages (with their own respective versions). This is really useful in cases where you would like multiple python versions for different tasks or when there is some conflict in versions of packages, required by other ones. By default, anaconda creates a "base" environment with a specific python version, IDLE and pip. Also, anaconda provides an improved way (with respect to pip) of installing and managing packages via the command conda install <package-name>.
For the rest, I will be using the word "vanilla" to refer to the python/installation that you manually set up, independent of anaconda.
Explanation of the problem:
Now, the problem arises since you also installed python independently. The details of the problem depend on how exactly you set up both python and anaconda, so I cannot tell you exactly what went wrong. Also, I am not an OSX user, so I have no idea how python is installed and what it downloads/sets alongside.
By your description however, it seems that the "vanilla" python installation did not overwrite neither your anaconda python nor anaconda's pip, but it did install IDLE and set it up to use this new python.
So right now, when you are downloading something via pip, only the python from anaconda is able to see that and not IDLE's python.
Possible solutions:
1. Quick fix:
Just run IDLE via /Users/myname/anaconda3/bin/idle3 every time. This one uses anaconda's python and should be able to see all packages installed via conda install of pip install (*). I get this is tiresome, but you don't have to delete anything. You can also set an "alias" in your ~/.bashrc file to make the command idle specifically linking you there. Let me know with a comment if you would like me to explain how to do that, as this answer will get too long and redundant.
2. Remove conda altogether (not recommended)
You can search google on how to uninstall anaconda along with everything that it has installed. What I do not know at this point is whether your "vanilla" python will become the default, whether you will need to also manually install pip again and whether there is the need to reinstall python in order for everything to work properly.
3. Remove your python "vanilla" installation and only use anaconda
Again, I do not know how python installation works in OSX, but it should be reasonably straightforward to uninstall it. The problem now is that probably you will not have a launcher for IDLE (since I am guessing anaconda doesn't provide one on OSX) but you will be able to use it via the terminal as described in 1..
4. Last resort:
If everything fails, simply uninstall both your vanilla python (which I presume will also uninstall IDLE) and anaconda which will uninstall its own python, pip and idle versions. The relevant documentation should not be difficult to follow. Then, reinstall whichever you want anew.
Finally:
When you solve your problems, any IDE you choose, being VScode (I haven't use that either), pycharm or something else, will probably be able to integrate with your installed python. There is no need to install a new python "bundle" with every IDE.
(*): Since you said that after typing pip install pandas your anaconda's python can import pandas while IDLE cannot, I am implying in my answer that pip is also the one that comes with anaconda. You can make sure this is the case by typing which pip which should point to an anaconda directory, probably /Users/myname/anaconda3/bin/pip
First: This would be a comment if I had enough reputation.
Second: I would just delete python. Everything. And reinstall it.
To repeat and summarized what has been said on various other question answers:
1a. 3rd party packages are installed for a particular python(3).exe binary.
1b. To install multiple packages to multiple binaries, see the option from python -m pip -h.
To find out which python binary is running, execute import sys; print(sys.executable).
3a. For 3rd party package xyz usually installed in some_python/Lib/site-packages, IDLE itself has nothing to do with whether import xyz works. It only matters whether xyz is installed for 'somepython' (see 1a).
3b. To run IDLE with 'somepython', run somepython -m idlelib in a terminal or console.
somepython can be a name recognized by the OS or a path to a python executable.

unable to use preinstalled python packages in Jupyter notebook

guys,
here's the problem. I have got access to a server with jupyter notebook. There are already several packages installed on this server, which I want to use. But unfortunately it doesn't work with all packages. E.g. pandas, numpy and others work but I have problems with sklearn and Tensorflow.
When I query the list of all installed packages via pip I see for example the installation of Tensorflow:
If I want to import the package I receive this message:
It's the same with sklearn. Other packages work. Since there are still several people working on this server I wouldn't like to reinstall packages or restart the server. Does anybody have an idea where my mistake is?
Thanks a lot and stay healthy!
There could be multiple versions of Python installed on the server.
And the version that pip is using does not have to be the same version as your notebook is running.
So first, check which version of Python your notebook is using; Open the File menu and click on New console for notebook. In the console you should see the Python version. Say it shows this:
Python 3.7.6
Then call python3.7 -m pip list to see which modules are actually installed for that version of Python.
Edit
Is there an easy way to tell only my juptyer notebook to take this version?
Use Change Kernel... from the Kernel menu.

Package not found in python, despite loading jupyter notebook from environment w/package

I have a fresh installation of Anaconda on OS X, and I'm following the instructions on this page to the letter, in order to create the appropriate environment.
When I enter conda list after activating the environment, pandas and matplotlib are both listed.
But when I open the provided jupyter notebook, or when I create a new jupyter notebook and type import pandas as pd, I get a 'there is no module called pandas' error. Ditto for matplotlib.
Happy to provide any more information that would be helpful in figuring out the problem. I feel like I run into problems like this a lot, so general strategies for debugging this kind of thing are welcome. Thanks!
EDIT: OK, I've fixed the problem for now, but I still feel like I'm missing something.
The problem was that there was no jupyter/ipython notebook kernel for the version of python in this env. So when I launch the notebook, even within the env, the correct version of python doesn't load, and some packages aren't available.
The solution is to add the kernel as described here: Using both Python 2.x and Python 3.x in IPython Notebook
It seems a bit odd to have to install a different ipython-kernel for every environment, but maybe it's not. I guess I just thought the correct version of python would load in the notebook as long as the notebook was launched from the env.
Does anyone have a better solution?
Since both your Py2 and Py3 kernels need different, version specific sets of packages to support them, the best and most convenient solution seems to be the one it sounds like you followed -- use anaconda, install either version as your default, then install an env with the other. If you want pandas available to both versions, you will need to make sure you conda install it in both the root and the other env. Jupyter is a bit magical in that it can be launched from either environment, yet will recognize that an ipython kernel exists in a different env and make both available to you.
It sounds like this may have worked against you slightly, though, and that you either launched jupyter from an env that didn't have ipython installed, but did have pandas. Jupyter found the ipython kernel in the other env, but you didn't have pandas installed there yet. At lest thats a theory. Solution remains to install pandas and ipython in both. Doing conda install anaconda in both envs will give you lots of packages, if space isn't a concern and may save you some of this aggrivation.

Categories