Never success to plotting graph by python igraph - python

So many times after i type plot(g, layout=layout) poping out the error message:
I installed Cairo and py2cairo successfully as the doc said, but it didn't work.
I'm using mac os 10.8.x and I use ipython to try to plot as the tutorial.

First, make sure the python's real path by which python
Then, check the sys.path of current python.
I found that the brew install cairo is not installed in the python sys.path, so I have to
add another PYTHONPATH:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
to my .bashrc.

Related

Problem with graphviz, ExecutableNotFound error

I have a problem with installing graphviz in PyCharm. Im using windows. I already installed graphviz library onto my PyCharm project, however error occurs when executing dot.render:
graphviz.backend.execute.ExecutableNotFound: failed to execute WindowsPath('dot')
I tried adding
import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'
as said here: "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38
but it still doesent work?
any ideas?
Im new to pycharm and advanced coding in general, go easy please...
This is a very common problem. While it may have several causes (see suggestions above), the solution you found is out-of-date.
Unfortunately, there are two software systems named Graphviz. You need both.
Go here https://graphviz.gitlab.io/download/ and download the appropriate version.
To check that you have installed the "real" Graphviz package, bring up a cmd window & type dot -V

Matplotlib crashes when importing pyplot in Blender

I know this question has been asked many times before but I cannot find a solution that works for me. I'm running Python 3.5.3 under Blender 2.79 in Windows 10. As I require Blender 2.79, upgrading the Python version is not possible.
I've installed matplotlib and I can import it. However, when I try to import pyplot (e.g. import matplotlib.pyplot as plt), I get a crash to desktop with no error messages of any kind. This happens if I run Python externally or from inside Blender. The weird thing is that I was able to avoid this by changing backends to agg (matplotlib.use('agg')) and this is still working in a previous installation (so I know it's possible to get this to work !), but not in a separate, new installation of Blender. I've tried other backends but they make no difference.
The exact procedure I've tried is as follows :
Downloaded Blender 2.79 from a zip file (I'm using Windows 10) and unpacked it (call this directory /Blender/)
In /Blender/2.79/python/bin I run the command ./python -m ensurepip
In /Blender/2.79/python/scripts I run pip3 install --upgrade pip --user. This gives me pip3 version 20.2.4
In the same directory I run pip3 install --target="/Blender/2.79/python/lib/site-packages" matplotlib --upgrade. The "upgrade" switch is to prevent warnings that the "/bin" directory exists. Doesn't make any difference if I remove it, there's no existing installation of matplotlib. This gives me matplotlib version 3.0.3
Finally I start Python by /Blender/2.79/python/bin/python.exe, and do the above mentioned importmatplotlib.pyplot command which causes the crash.
I've tried this from a completely fresh installation of Blender, which comes with no existing external modules installed. Could there be some conflict with other Python modules elsewhere ? How would I go about diagnosing what's going on ?
Thanks for any ideas !
FIXED ! I remembered I found the solution months ago, but stupidly wrote down the answer in the wrong file...
The problem is that matplotlib is looking for a file that doesn't exist. In c:/users/me/.matplotlib (a hidden file), there's a file ""fontlist-vXXX.json", where XXX is the version number. This is set in line 951 of the file "font_manager.py", located in /python/lib/site-packages/matplotlib. In my case, the font_manager was looking for version 300 but the actual file was 310. Changing the version number in the font_manager.py made everything work correctly.

So i installed numpy . But when i call it in a program an error occurs. Any method to solve it permanently in windows 10

Here is the error
import numpy
Exception has occurred: ModuleNotFoundError
No module named 'numpy'
File "C:\path\to\file\32.py", line 1, in <module>
import numpy
Let me know how did you install the NumPy package; using pip or something else?
If you have multiple python versions, i.e. 2.x and 3.x at the same time, please make sure your interpreter for the 32.py file is the version that you installed NumPy on.
To possibly fix your problem, you should first try installing it and see if there are any errors. You should also check the version of Python you are running on Windows 10, because when you update Python it sometimes switches names between py and python
As you can see, the version of Python has changed between py and python so you should try changing that first.
If this does not work, you should try finding the directory for NumPy and adding it to the system PATH in your script. The installer usually shows you the location by doing the following:
import sys
sys.path.append("<insert numpy location here>")
import NumPy
This should manually force it into finding the package. If none of this works, please tell us and we should be able to find a different solution.
Happy Coding!
If you're using a code editor like PyCharm, you could install it by clicking on
file then settings then the project interpreter setting and install new module! You can search for the module and install.
Make sure that the python version that you want to use is a Windows Environmental Variable. You can test this by running this line in your command line.
> python --version
If you get some other python version that is not the one that you wish to use you can set the python version you want by finding where exactly your Python folder is located and go into settings and set the path as a new variable (I can leave a tutorial for you). If that is too much of a hassle, the Python installers can set the python that you will install as an environmental variable for you. (You could uninstall and reinstall and make sure that you allow it to make it an environmental variable.
After that you should be able to import whatever external packages you want using pip
for example:
pip install numpy

Error importing Polygon from shapely.geometry.polygon

In my Anaconda 2.2 64bit with Python 3.4.3 the following line works well:
import shapely
But the following line:
from shapely.geometry.polygon import Polygon
returns the following error:
OSError: [WinError 126] The specified module could not be found
What am I missing?
EDIT
I tried with iNotebook, idle.exe and Eclipse. They all use Anaconda (the only Python installation on my computer) and they all show the same error.
If I type from shapely.geometry import Polygon in Eclipse, then I click on Polygon, then I press F3, Eclipse is able to open the module C:\Anaconda3\Lib\site-packages\shapely\geometry\polygon.py. So Eclipse is able to find it, but the execution fails.
EDIT 2
I just tried the same import on another computer with similar configuration and it works. The "only" difference between the two computers is that one has Windows 7 (it works) and one has Windows 8 (it doesn't).
I installed Anaconda and a few packages in both the computers following the same old checklist. The computer with Windows 8 can see the package from Eclipse, but can't import it.
I had a similar problem and it was due to the way that I improperly installed shapely (although this was on a Windows 7 machine, not Windows 8). For the initial install under which I couldn't import the geometry sub-module I installed shapely with the command:
pip install shapely
However after reading the documentation here more closely I saw that for Windows an executable installer needed to be used. That installer is a wheel file that needs to be launched by pip as well. So I uninstalled the first version of shapely with:
pip uninstall shapely
Then I launched the installer via the wheel file like this:
pip install your/file/path/Shapely‑1.5.9‑cp27‑none‑win32.whl
Note that you must download the wheel that matches the specs of the version of python that your applying the package to. I have 32-bit (win32) python 2.7 (p27) so the package above was the correct one. Note that the reference to 32 or 64 bit in the file name refers to the version of python, not to the version of windows.
Try with below one, it solved the issue for me (Windows 10):
conda install -c conda-forge shapely
shapely package docs
Try this:
from shapely.geometry import Polygon
That's how the docs list it:
http://toblerity.org/shapely/manual.html#polygons
Don't use anything but Python version 3.7. Download it now!
Then go to PyCharm (that's what I'm using) and open it, then download the file for your specific version (from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely) mine is Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl (this is respectively version 3.7 (37) and Windows (64) as seen above)
Now with your newly downloaded file, copy and paste it into where you are working from in PyCharm's folder location. For me this is: C:\Users\lewis\PycharmProjects\Project1\NewProject
Then you should see the newly copied file in PyCharm itself as well as where you put it.
Now right click the file in PyCharm Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl
and click OPEN IN TERMINAL then type:
pip install Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl
It should say "successful".
Then go into your working area and type:
from shapely.geometry import point
Run it. It should now work for all!
Be in mind that this will ONLY allow for the importing of Shapely in this one environment. So you'll have to copy the Shapely file into new folder locations if you use in other places.
Specs:
Be in mind I am working with a Windows 10, Python interpreter version 37, PyCharm, Virutalenv environment type. Also, make sure in the settings you are indeed in the Python 37 interpreter and not in a conda environment.

How to set ffmpeg for matplotlib in mac os x

I want to animate some plots with matplotlib. The version I have is the Enthough Canopy distribution (Version: 1.1.0.1371), running in a mac os x 10.8 (Mountain Lion). I have used the FuncAnimation routine from the animation package of matplotlib. My problem comes saving the animation. I want to save in mp4 format:
anim.save('test.mp4',fps=30)
The error I get is:
UserWarning: MovieWriter ffmpeg unavailable
warnings.warn("MovieWriter %s unavailable" % writer)
So I installed ffmpeg via Macports. But I am still having the same error. Do you know how to setup matplotlib in order to recognise ffmpeg? Do I have to change the matplotlibrc file?
Thanks.
EDIT: I have realized that I can manually put '/opt/local/bin' in the PYTHONPATH, but it does not change the PATH in Enthough Canopy. Do anyone know how to change the PATH in canopy?
I had the same problem. My solution was very simple.
Download the binary from here.
Then do
sudo mv ~/Downloads/ffmpeg /usr/bin/
I had success when installing with homebrew:
brew install ffmpeg
After that set up the FFMpegWriter yourself by:
mywriter = animation.FFMpegWriter()
anim.save('mymovie.mp4',writer=mywriter)
I think the solution can be found in the workaround in this and this post.
It seems that the path of the shell is not loaded by matplotlib, and since macports are installed in /opt/local/bin, ffmpeg can't be found.
Either go for the hack described above, try making a symlink in /bin for ffmpeg, or try adding the path to ffmpeg to the python path as suggested in the comments of the second link

Categories

Resources