ImportError Python cannot import name - python

I am trying to reproduce a code from a scientific publication which uses Python 2:
https://github.com/TeamErlich/dna-fountain
The code is based on Python 2 so I had to change my environment to Python 2 from Python 3. Anyways, when I ran the code I realized that Python is not able to import DNAFountain from fountain, although I successfully installed it with pip install fountain. I constantly receive this error message:
File "encode.py", line 9, in <module>
from fountain import DNAFountain
ImportError: cannot import name DNAFountain
Does anybody know why my code is not able to import DNAFountain?

Related

Pyinstaller - ModuleNotFoundError: No module named 'cpuinfo' [duplicate]

This question already has answers here:
Pyinstaller 'failed to execute' script
(2 answers)
Processes stuck in loop with PyInstaller-executable
(1 answer)
Closed 20 days ago.
I'm trying to package this script but I keep getting this error message
Traceback (most recent call last):
File "systeminfo.py", line 1, in <module>
ModuleNotFoundError: No module named 'cpuinfo'
[6308] Failed to execute script systeminfo
I tried this into cmd
pyinstaller -F --hidden-import="cpuinfo" systeminfo.py
I'm on the latest version of pyinstaller and pip.
This is the import section of my file:
import psutil, platform, GPUtil, cpuinfo, os, sys, wmi, winreg, getpass
from tabulate import tabulate
from datetime import datetime
When I run it, it just opens up and closes out. But when I run it through CMD, that's when I get that error message.
How do I fix this? I want to include all the modules so I can run this script on different computers that don't have python installed.
EDIT:
I fixed this issue by using this thread: Pyinstaller 'failed to execute' script
I use pycharm so this worked for me.
The only issue is whenever the CMD opens up, nothing happens. The only thing that can printed is if I hardcode a print(). Functions aren't working at all.
fix it with :
pip install py-cpuinfo

Problem with importing rospy and roslib libraries

I am new to ROS and python. This question could be silly but spent almost 5 hours on this. I am using PyCharm (Latest version) with Python 2.7.15 64 bit (Also tried with 3.x). I need to import a few libraries as below:
import roslib;
roslib.load_manifest('smach_tutorials')
import rospy
import smach
import smach_ros
However, PyCharm fails to identify roslib, rospy, smach and smach_ros (could not find in the interpreter also to import). The above libraries are example given in the official site:
http://wiki.ros.org/smach/Tutorials/Simple%20State%20Machine
OS: Windows 7 (64 bit)
ROS not installed: ("SMACH is a ROS-independent Python library to build hierarchical state machines" - from the official site)
Error Traceback:
Traceback (most recent call last):
File "C:/Users/****/Desktop/Python/TestCharm.py", line 3, in <module>
import roslib;
ModuleNotFoundError: No module named 'roslib'
If you are using the catkin version of ROS (Groovy and later), it does not use the manifest file but uses the package.xml file instead.
So your code will be:
import rospy
import smach
Apparently, your code is ready for ROS Fuerte or earlier version.
With supposing that Smach is ROS-independent, you need only to the import smach
Thanks for all the support. I found out it is not possible for my perticular case to use SMACH because it has dependency on catkin. I am using Windows 7 and should be upgraded to windows 10 or use Ununtu Linux.

Import Error in __init__.py : No Module named _vlfeat in PyVlfeat

I am trying to run this python rewrite of Vlfeat library.
https://github.com/shackenberg/phow_caltech101.py. I am trying to run the application phow_caltech101.
This is throwing
File "/A/B/C/pyvlfeat-0.1.1a3/vlfeat/__init__.py", line 1, in <module>
import _vlfeat
ImportError: No module named _vlfeat
In the corresponding "init.py" file, I can see it is mentioned as "import _vlfeat". I am new to python, please let me know what is causing this error?
You need to download and install PyVlfeat module.
https://pypi.python.org/pypi/pyvlfeat/
As I see, pyvlfeat has some dependencies, so be sure to download these too:
Boost.Python (tested against version 1.35.0-5)
NumPy (tested against version 1.5.1)
Matplotlib (tested against version 0.99.3)

Python Import Error: cannot import name 'literal_eval'

I'm getting the following error while running the python program. I'm using python 3.4 and I have installed Ferenda-0.1.7-py3.4 And the error is:
File "C:\Python34\lib\site-packages\ferenda-0.1.7-py3.4.egg\ferenda\util.py", line 20, in module
from ast import literal_eval
ImportError: cannot import name 'literal_eval'
Appreciate you help on this. Thank you.
When I tried running in the command prompt. I can see no errors. Attached is the picture
You have named your script ast.py (or you have another script in the same directory named ast.py) and this script does not contain a literal_eval.

Scons fails to import _args_from_interpreter_flags

Im trying to compile Godot engine following the instructions here
When I run scons bin/godot as the tutorial says, I get the following error:
scons: Reading SConscript files ...
ImportError: cannot import name _args_from_interpreter_flags:
File "/home/grayfox/github/godot2/godot/SConstruct", line 9:
import multiprocessing
File "/usr/lib64/python2.7/multiprocessing/__init__.py", line 65:
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib64/python2.7/multiprocessing/util.py", line 40:
from subprocess import _args_from_interpreter_flags
The SConstruct file starts this way:
EnsureSConsVersion(0,14);
import string
import os
import os.path
import glob
import sys
import methods
import multiprocessing
...
If I try to run python SConstruct I get an error complaining about missing functions defined by scons (i.e. the script fails after doing all the imports).
Commenting import multiprocessing fixes the issue but I don't want to modify that file, as I would have to revert the change if I ever make a pull request. The project is quite active so I believe this has something to do with my local configuration.
Any ideas why the script is failing to import _args_from_interpreter_flags only if I execute it via scons?
[UPDATE]
I did a fresh Gentoo install and the problem persists. I did some tests and I found this:
In a python terminal>
>>> import SCons.Script
>>> from subprocess import _args_from_interpreter_flags
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name _args_from_interpreter_flags
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/site-packages/SCons/compat/_scons_subprocess.pyc'
But the output is different if I do this:
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/subprocess.pyc'
So I update my question: Is this a bug? Can anybody reproduce it in other distros? If it's a bug, should I report it to Gentoo or to SCons?
[ANOTHER UPDATE]
Adding temp.extend([os.path.join(x, 'lib64') for x in prefs]) did't work, same error.
Adding print sys.path at the beginning of the compact module gives:
['/usr/lib64/python-exec/python2.7/scons-local-2.3.0',
'/usr/lib64/python-exec/python2.7/scons-local',
'/usr/lib64/python2.7/site-packages/lib32/scons-2.3.0',
'/usr/lib32/scons-2.3.0',
'/usr/local/lib32/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib/python2.7/site-packages/scons-2.3.0',
'/usr/local/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib64/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib32/scons',
'/usr/lib32/scons',
'/usr/local/lib32/scons',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons',
'/usr/lib/python2.7/site-packages/scons',
'/usr/local/lib/python2.7/site-packages/scons',
'/usr/lib64/scons',
'/usr/lib64/python2.7/site-packages/RBTools-0.6-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7', #It's here, so what's the problem?
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode']
It looks as if this isn't really a problem connected to SCons directly. You might have an alien "subprocess" module/package installed in your system. Also check out Cannot import name _args_from_interpreter_flags which seems to be related.
Based on your updated question: I tried to compile Godot on my machine (Python 2.7.3, SCons 2.3.1, Ubuntu 12.04 LTS) and it's running fine, so the problem is not related to the provided SConstruct (and its supporting build description files in subfolders). The "_scons_subprocess" module gets used only when the import of the original "subprocess.py" fails. So I suspect that the SCons start script sets up a wrong sys.path, which may happen under 64bit (see issue http://scons.tigris.org/issues/show_bug.cgi?id=2657 ).
After you added "temp.extend([os.path.join(x, 'lib64') for x in prefs])", your "print sys.path" statement shows paths like "/usr/lib64/python-exec" in its output. A Google search turned up the page http://forums.gentoo.org/viewtopic-t-985402-start-0.html for me. It describes an issue with Gentoo, where programs are installed as links to pip. Please follow the given advice and see if this fixes your problem.
It's a bug in Gentoo's scons-2.3.0 and scons-2.3.1 ebuilds (see bug report). It has been fixed in versions 2.3.1-r1 and higher.

Categories