Pip install does not work, matplotlib seems to be broken, pyenv and fresh new install doesn't work - matplotlib

So I wanted to import matplotlib to my virtual python version of 3.10.0 (and other versions). I install it as usual:
pip install matplotlib
Everything seems to work, no errors show up with pip. But when I try to run this code snippet in vs code (to see if mpl works):
import matplotlib
print(matplotlib.__version__)
It outputs this:
File "/Users/XYZ/Desktop//pienv.py", line 1, in <module>
import matplotlib
File "/Users/XYZ/Desktop//matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
But when I do the same in the terminal it outputs the correct version.
It doesn't matter if I have python installed with dmg file or with pyenv, result is the same.
I tried to format operating system to ensure there is no os trash that might be getting in a way. Then I just installed python with pyenv.
I'm using osx 12.0.1
My vscode setup is straightforward, just python extension and python interpreter set to what pyenv has as a local python.
Is there that can be done, or that I'm doing wrong?

Found the answer.
It's just a stupid thing.
Don't name your projects with the names of your libraries when they're in the same directory.

Related

Cartopy: importing from new install results in symbol not found in flat namespace '_GEOSCoordSeq_create_r'

I'm setting up a new MacBook and testing the code that I ran on my old Macbook.
One module I need is cartopy. I have installed it using the MacOS instructions detailed here -> https://scitools.org.uk/cartopy/docs/latest/installing.html
This all installs no problem. However when I try to import cartopy I hit the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cartopy/__init__.py", line 107, in <module>
import cartopy.crs # noqa: E402 module-level imports
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cartopy/crs.py", line 27, in <module>
import cartopy.trace
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cartopy/trace.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_GEOSCoordSeq_create_r'
Tried uninstalling proj downgrading to proj7 via homebrew then uninstalling and reinstalling cartopy -> no effect
Tried uninstalling and reinstalling geos via homebrew then uninstalling and reinstalling cartopy -> no effect
Tried uninstalling and reinstalling shapely for versions earlier than 2 then uninstalling and reinstalling cartopy -> no effect
Tried installing cartopy via conda with conda install -c conda-forge cartopy -> this results in a package which I can import but which contains none of the cartopy functions and only basic functions from the "string" package.
My current versions are
cartopy 0.21.0
shapely 1.8.5.post1
geopandas 0.11.1
geos 3.11.0
proj 9.1.0
Has anyone hit this problem before and solved it?
Sorry for asking but I've been stuck on this for ages.
I managed to get cartopy installed via conda but only in the default anaconda environment. That will do but still no idea why I couldn't get it working from pip using the instructions on the cartopy site

Installed BeautifulSoup but still get no module named bs4

I'm using a Jupyter notebook, Python 3.5, and a virtual environment.
Within my virtual env I did:
(venv) > pip install BeautifulSoup4
Which seemed to run fine b/c the terminal output was:
Downloading beautifulsoup4-4.6.0-py2-none-any.whl (86kB)
100% |████████████████████████████████| 92kB 297kB/s
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.6.0
But when I run my Jupyter notebook I get:
ImportError Traceback (most recent call last)
<ipython-input-1-5fe69888b1a1> in <module>()
5 from itertools import groupby
6 import pickle
----> 7 import bs4
8 import matplotlib.pyplot as plt
9 get_ipython().run_line_magic('matplotlib', 'inline')
ImportError: No module named 'bs4'
And I can't change the line import bs4 to from bs4 import BeautifulSoup which I've seen on other SO posts b/c its read-only and I'm not supposed to
Since you are using Python 3, I think you needed to do
pip3 install BeautifulSoup4
Just pip install would have been for the Python 2 package.
Other things to check:
First make sure you ran both the BeautifulSoup install in your virtualenv, and the python3 prompt or Jupyter notebook in your virtualenv. If you did the install in your root environment and the notebook is run in your virtualenv, or vice versa, you might have a mismatch in your site-packages directory.
Ensure that your package indeed installed by typing pip3 list at a command prompt, and noting that it appeared in the list.
Check that you Jupyter notebook is indeed running a Python 3.5 kernel (upper right hand corner of the browser window)
Check that the path where the package is installed is in your sys.path
Open a Python3 prompt or in Jupyter and run
import sys
print (sys.path)
I had the same problem, bs4 was installed in my virtual environment along with Jupyter Lab. Jupyter would throw the ModuleNotFound Error but if I opened the notebook in Visual Studio Code and chose the .venv as the interpreter, it worked.
I got it to work in Jupyter Lab by uninstalling from the virtual environment and installing with sudo apt-get install python3-bs4 instead.

No module named 'pandastable'

I'm trying to change table wrote by me on tkinter with the pandastable one in order to do the handling of data directly from a pandas.DataFrame.
But despite I have already installed Anaconda3 with matlplotlib, numpy, pandas ect. modules when i would like to import pandastable I have trouble.
This is the problem:
import pandastable
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import pandastable
ImportError: No module named 'pandastable'
pip install pandastable
Requires python>=3.3 or 2.7 and numpy, matplotlib and pandas.
See: pandastable on github
edit: You may have multiple Python environments installed on your machine. Anaconda uses conda install to keep things in check but pandastable doesn't seem to be available through Anaconda packages. Make sure you are installing to the same Python environment that your script uses. You might also try:
pip3 install pandastable

How can I install mpmath as an external library for Blender?

I'm interested in trying out sympy with Blender (v2.76, Python 3.4.2 Console, Windows 8.1). I followed this answer from Blender SE, downloaded sympy as a ZIP from Githib, and moved the sympy folder to C:\Program Files\Blender Foundation\Blender\2.76\python\lib\site-packages. However, when I opened Blender and tried to import sympy in the Python Console, I got the following error:
>>> import sympy
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.76\python\lib\site-packages\sympy\__init__.py", line 20, in <module>
raise ImportError("SymPy now depends on mpmath as an external library. "
ImportError: SymPy now depends on mpmath as an external library. See http://docs.sympy.org/latest/install.html#mpmath for more information.
I don't know how to install an external library. I tried going to the link mentioned in the ImportError, and I saw pip install mpmath. I tried it in cmd, but got this:
>pip install mpmath
Requirement already satisfied (use --upgrade to upgrade): mpmath in c:\anaconda3
\lib\site-packages
I did install Anaconda a while ago, so I guess it makes sense to have this output. How can I install mpmath as an external library for Blender so I can import sympy in it?
You want to install mpmath into blenders python folder, the same as you have done for sympy.
Your example of running pip was done in a system installed python that is setup to find the mpmath that you have installed in c:\anaconda3\lib\site-packages
Another option is to use the existing install of mpmath and sympy by adding your existing path to sys.path or adding it to the PYTHONPATH environment variable before you start blender.

How to install modules for Python 2.7 on Ubuntu 10.10?

On Ubuntu 10.10, I am unable to install lxml to python 2.7. Here are the steps I take.
sudo su -
apt-get install python2.7
apt-get install python-lxml
Note when running the install for python-lxml package, the following appeared:
INFO: using unknown version '/usr/bin/python2.7' (debian_defaults not up-to-date?)"
Importing the module in python2.6 (the version that comes standard with Ubuntu) works. However, importing the module under python2.7 does not. So how does one install Python modules to a non-default Python installation?
Try to install libxml2, libxml2-dev, libxslt, libxslt-dev, python-dev. These are header files. Then try to install lxml again.
On Ubuntu 10.10 the python packages installed from the repositories get installed to /usr/lib/python2.6/dist-packages so one option is to add this path to your $PYTHONPATH environmental variable so python2.7 will look to the python2.6 directory for the libs.
What I've done on Ubuntu 10.10 is add
export PYTHONPATH="$PYTHONPATH:/usr/lib/python2.6/dist-packages"
to my .bashrc file, and also to my .gnomerc file. This sets the $PYTHONPATH for python instances started from the shell or from the gnome desktop. You should then be able to import the python libs which you have installed from the Ubuntu repositories in python2.7.
.bashrc and .gnomerc are both located in your home directory; you might have to create .gnomerc if it doesn't already exist. And one caution: I had a syntax error in my .gnomerc which stopped the gnome desktop from loading, and I couldn't log in. I had to use a recovery console to fix this syntax error and then I could log in again.
This seems a little hackish to me, so I'm interested in hearing better solutions.
Another solution might be to use the following code:
try:
from lxml import etree
except ImportError:
try:
# Python 2.5
import xml.etree.cElementTree as etree
except ImportError:
try:
# Python 2.5
import xml.etree.ElementTree as etree
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
except ImportError:
print("Failed to import ElementTree from any known place")
[Source]
This will import lxml if it is available, or the original ElementTree otherwise.
I use this code for my application on Google App Engine (using Python 2.7): on the server it will use lxml, on my machine it will use ElementTree.
I have one easiest trick Just open synaptic package manager type "python-lxml" in search box it will show you all the dependencies and available packages select packages which you want to install and hit apply.