Igraph runs in Python console but not from script - python

I've installed igraph on Python 3.7.2 using the wheel at https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-igraph and 'pip install python-igraph'. I attempted to create a simple graph with:
import igraph
g = igraph.Graph()
This works when I run it in the console (IDLE) but when I write it in a script and execute it, the second command gives the following error:
Traceback (most recent call last):
File "path\igraph.py", line 1, in <module>
import igraph
File "path\igraph.py", line 3, in <module>
g = igraph.Graph()
AttributeError: module 'igraph' has no attribute 'Graph'
Previously I wrongly used 'pip install igraph" but later uninstalled it.

Most likely, you named your executable file igraph.py, so there is a name conflict. Just rename the file

Related

julia.install() fails on python import error

I am trying to run a Julia script from python. I have Julia 1.6.4 installed (also tried 1.7.3) and installed pip install julia from Pycharm's terminal in the virtual environment. When importing julia and then running julia.install() I get the following error message:
I use Pycharm with a virtual environment with Python 3.9.7 for my project. However, I have also tried different python versions in different virtual environments or by using the base python installed. All give the same error.
Also, ~/.julia/packages/PyCall/*/deps/build.log does not exist for me.
[ Info: Trying to import PyCall...
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\site.py", line 73, in <module>
import os
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\os.py", line 29, in <module>
from _collections_abc import _check_methods
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\_collections_abc.py", line 12, in <module>
GenericAlias = type(list[int])
TypeError: 'type' object is not subscriptable
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\<user>\PycharmProjects\<project>\venv\lib\site-packages\julia\tools.py", line 118, in install
raise PyCallInstallError("Installing", output)
julia.tools.PyCallInstallError: Installing PyCall failed.
** Important information from Julia may be printed before Python's Traceback **
Some useful information may also be stored in the build log file
`~/.julia/packages/PyCall/*/deps/build.log`.```
Julia needs to have PyCall installed
PyCall in Julia needs to be configured to use the same Python that you are using to call Julia from
For more information see this post:
I have a high-performant function written in Julia, how can I use it from Python?

Can't import pymatgen.core "No module named 'pymatgen.core'"

I've used pip install pymatgen with Python 3.9.1 on Windows 10 to install pymatgen, but I'm getting the following error:
Traceback (most recent call last):
File "D:\code\pymatgen\pymatgen.py", line 1, in <module>
import pymatgen.core as mg
File "D:\code\pymatgen\pymatgen.py", line 1, in <module>
import pymatgen.core as mg
ModuleNotFoundError: No module named 'pymatgen.core'; 'pymatgen' is not a package
I have also tried to install the previous 2 versions but still getting the same error though I can already see it in the pip list
pymatgen 2022.3.22
What am I missing?
Maybe try using conda ? if this doesn't work then there is definitely some dependencies issue
https://pymatgen.org/installation.html

unable to find whois library

I am trying "whois" with python.
I installed whois for python using following code (OS:- CentOS 7)
pip install python-whois
when I run following three commands at python console it works
import whois
w = whois.whois('www.google.com')
print w
But when same three lines I save in file whois.py and run code with command
python whois.py
It gives following error
Traceback (most recent call last):
File "whois.py", line 1, in <module>
import whois
File "/home/sysadmin/pythonPractice/whois.py", line 2, in <module>
w = whois.whois('www.google.com')
TypeError: 'module' object is not callable
this issue is because your filename is whois.py and when you try to call the library whois it gets overwritten so, you should name your file from whois.py to something else.

Can't find submodule in package

I'm using Anaconda3 version 4.2.0 on ubuntu (in docker).
Anaconda is installed in /root/anaconda3 folder.
I installed theano_bpr package using pip install theano_bpr.
Now when i open python and try import theano_bpr, i get the following message:
>>> import theano_bpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/anaconda3/lib/python3.5/site-packages/theano_bpr/__init__.py", line 17, in <module>
from bpr import BPR
ImportError: No module named 'bpr'
However, when i navigate to /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ and run python there, i'm able to import theano_bpr.
In /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ there are following files:
__init__.py, bpr.py (this one is causing problems), t.py, and utils.py.

Python igraph import error on Windows

I've installed igraph form .whl file using pip install. When I was trying to test the correctness of installation
import igraph.test
igraph.test.test()
I got this error:
Traceback (most recent call last):
File "D:/Nauka/Praca-inzynierska/Barabasi-Albert.py", line 4, in <module>
import igraph.test
File "D:\Programy\Python 3.5\lib\site-packages\igraph\__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: No module named 'igraph._igraph'
(the same error pops out if I'm trying to import igraph not igraph.test).
I've tried adding path (I don't know if this is rigth):
import sys
sys.path.append ("D:/Programy/Python 3.5/Lib/site-packages/igraph")
but it didn't work.
One thing I discovered is that if I delete "__init__" file from igraph folder I can import igraph without error, but it doesn't work for igraph.test.
If it's relevant I have Python 2.7 installed on my machine alongside Python 3.5.
Thank you in advance for any help.

Categories

Resources