bottle: can not import route - virtualenv

I am getting the following error:
(virtualenv)[chirdeep#fedora-desktop ~]$ python programs/python/myrestapi.py
Traceback (most recent call last):
File "programs/python/myrestapi.py", line 2, in <module>
import bottle
File "/home/chirdeep/programs/python/bottle.py", line 1, in <module>
from bottle import route, run
ImportError: cannot import name route
I have got python 2.7.3 and 3.2.3. (virtualenv) is pointing to python3 and I have installed bottle in here and its available under site-packges..
I can import bottle when I am under python console after activating the environment.
(virtualenv)[chirdeep#fedora-desktop ~]$ python
Python 3.2.3 (default, Jul 26 2012, 22:03:19)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
>>>
Any help will be much appreciated, driving me mad.
Thanks

Your own Python file is called bottle.py:
File "/home/chirdeep/programs/python/bottle.py", line 1, in <module>
So the real bottle.py is shadowed by your own file. Since your own file does not contain route and run, this fails:
from bottle import route, run
Rename your own file, perhaps mybottle.py.

I'm guessing the issue has to do with the collision of your program's namespace with bottle. I.e.: Python is trying to import route from /home/chirdeep/programs/python/bottle.py rather than the bottle.py in site-packages.
Try renaming your program file.

Related

vtkCommonCorePython missing error in python3-paraview on Ubuntu 20

I'm trying to use paraview scripting within python3 for Ubuntu 20.04.1 LTS. If I open python3 on the command line I get the error
$> python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from paraview.simple import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/paraview/simple.py", line 41, in <module>
from paraview import servermanager
File "/usr/lib/python3/dist-packages/paraview/servermanager.py", line 56, in <module>
from paraview.modules.vtkPVServerImplementationCore import *
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVServerImplementationCore.py", line 2, in <module>
from . import vtkPVClientServerCoreCore
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVClientServerCoreCore.py", line 2, in <module>
from . import vtkPVCore
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVCore.py", line 2, in <module>
from . import vtkClientServer
File "/usr/lib/python3/dist-packages/paraview/modules/vtkClientServer.py", line 3, in <module>
from .vtkClientServerPython import *
ImportError: Failed to load vtkClientServerPython: No module named vtkmodules.vtkCommonCorePython
>>>
I have python3-paraview, paraview, paraview-dev, vtk7, python3-vtk7, etc installed from the synaptic installation manager. There are two files with vtkCommonCorePython inside the dist-packages directory :
/usr/lib/python3/dist-packages/vtk/vtkCommonCorePython.cpython-38-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/vtkmodules/vtkCommonCorePython.cpython-38-x86_64-linux-gnu.so
Searching the internet shows that other people have had similar problems, and solved it but including the paths to vtkCommonCorePython, but sys.path does include /usr/lib/python3/dist-packages, so vtkCommonCorePython should be found.
Can anybody see what might be missing in this case?
Many thanks! John
There are (or at least there were in previous versions) some slightly tricky conflicts between the vtk and paraview packages in python. I've found it's best to keep paraview for python in its own conda environment.
Assuming you have conda already, you should be able to get up and running with:
conda create -n paraview -c conda-forge paraview

conda pyqt import failed in a new virtual environment

I tried to run programs using pyqt.
It worked if I didn't use a virtual environment but if I activated a virtual environment, it would fail: ImportError: DLL load failed...
Traceback (most recent call last):
File "submitA2.py", line 14, in <module>
import matplotlib.pyplot as plt
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import (
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\backend_qt5.py", line 18, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
import matplotlib.backends.qt_editor.formlayout as formlayout
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 56, in <module>
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_compat.py", line 137, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.
I can't install another pyqt package in this virtual environment because it tells me:
# All requested packages already installed.
# packages in environment at C:\Users\jerem\Anaconda3\envs\deep:
#
pyqt 5.6.0 py36_4 conda-forge
How to fix this?? Thanks.
A not perfect solution: installing a different version of PyQt5 seems to get around this issue.
activate myenv
conda install pyqt=5.9
Jeremy Chen's solution is the only solution that worked for me. i.e
conda install pyqt=5.9 within your conda environment
All other solutinos listed on internet did not work.
But this installation of pytqt=5.9 breaks matplotlib module with the following error when trying
import matplotlib
ImportError: cannot import name 'get_backend'
This was solved by using
conda uninstall matplotlib
and then reinstalling
conda install matplotlib

Import error ROS python3 opencv

Is there a way where I can import both opencv2 and rospy successfully in python3. Because right now I get an error.
Traceback (most recent call last): File "", line 1, in ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
removing the line "source /opt/ros/kinetic/setup.bash" from my bash file solves the problem of importing opencv but now I cant import rospy
This happens since ROS creates its own open cv ,which is compatible with python2 only.To solve this
You need to rename the Cv of Ros located at /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so to something else, example cv_renamed.so and then you should be able to import it
Since Ros cannot coexist for python2 and python3 , It is recommended to have a virtual environment(conda,virtual env)

Unable to import modules in Orange python environment but Orange GUI works

I would like to use the Orange.associate and Orange.data.sql modules in python scripting but in both cases I get AttributeError after import Orange.
However, in the Orange GUI both widgets work as expected.
When I check the python path with sys.path, the python interpreter has access to the Orange libraries, the global dist-packages and the local site-packages.
I have ubuntu 14.04 running and I installed Orange 3.3 into the /opt directory, following the instructions here:
http://orange.biolab.si/download/linux/
I am very unfamiliar with python environments and quite a beginner with Linux as well, so any hint is appreciated.
Here is an example of what I did:
(orange3env)bdukai#balazs-dukai:/opt/orange$ python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Orange
>>> Orange.data.sql
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sql'
>>> Orange.data.Table
<class 'Orange.data.table.Table'>
Import in python does not import submodules (subpackages) automatically. If you want to use Orange.data.sql, you should import it directly:
>>> import Orange.data.sql
>>> Orange.data.sql
<module 'Orange.data.sql' from '.../Orange/data/sql/__init__.py'>

Import Requests Error

I am starting to use requests lib and beautifulsoup lib. My goal is to extract data from Twitter, and do some hot topic analysis.
After I installed Python 2.7.5 on windows 7 system, I can import urllib2, but I can not import requests or BeautifulSoup.
Here is the error message below. Can someone help me here?
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
>>> import requests
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module>
import requests ImportError: No module named requests
I have googled a lot but find little hint on my situation. If you think that more info is needed to solve the problem, please leave a note here, I will be more than glad to provide the info that's needed.
Any help will be appreciated. Thanks!
I had a similar problem.
Mac OSX, IDLE Python 3.6:
Installed the module requests using the following commands:
import pip
pip.main(["install","--user","requests"])
The result was:
Successfully installed requests-2.12.4
But then I could not import the module requests using the command "import requests". But also not the command "import requests-2.12.4" was running in the IDLE. Running on a shell starting with "python3" I could run the standard import command "import requests" successfully.
So I did quit the IDLE and started it new. And then it did run as expected.
Maybe this helps you too!