Hide unresolved import error - python

I work with the Python plugin for Eclipse : PyDev on Linux and I'm writing a cross-platform application.
In this application, I have the following lines code :
try :
from win32com.shell import shellcon, shell
appdata_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
except :
appdata_path = os.environ['APPDATA']
PyDev show me 2 errors :
Unresolved import: shell
Unresolved import: shellcon
These errors appears because the pywin32 extensions aren't installed on my system and I can't install it because there are windows extensions, not linux.
Is it have a way to hide or ignore (only) these errors ?
Thanks

Click Ctl + 1 on the failing import line and select #UnresolvedImport error
or manually, make like this:
import Afailure ##UnresolvedImport

Related

Visual studio code cant find python import

Visual studio code cant find imports that are obviuously installed.
No tensorflow no pygame no nothing.
I used """pip install """ for everything, And it wont find it.
Pycharm does find it but only by downloading it using pycharm.
I have no idea what to do.
And this is the error message:
"""
Exception has occurred: ModuleNotFoundError
No module named 'tensorflow'
File "D:\a game 2\python\github\computer\main.py", line 3, in
import tensorflow
"""
And for some reason i get this error for every file, not just with custom imports:
"""
pyenv : File C:\Users\rocko.pyenv\pyenv-win\bin\pyenv.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
pyenv shell 3.10.0b3
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
"""
Have you tried changing the Python version used? Press [ctrl] + [shift] + [p] and search for select Python: select interpreter.

Python: ImportError for a module in a script launched from command line

There is a custom module "ETPython" generated by SWIG (consists of ETPython.py and binary _ETPython.so) and a simple script that invokes this module
sample.py
import ETPython
...
There aren't any problems if the script is run in an IDE (pycharm, internal python's IDLE, squish by froglogic so on). But if I'm trying to launch it in python shell in interactive mode or via terminal using
python3 sample.py
there is an error message like:
File "<path_to_file>/example.py", line 12, in <module>
import ETPython
File "<path_to_file>/ETPython.py", line 15, in <module>
import _ETPython
ImportError: dlopen(<path_to_file>/_ETPython.so, 2): Symbol not found: _NSLog
Referenced from: <path_to_file>/_ETPython.so
Expected in: flat namespace
Searching topics, I found that problem is related to wrong paths. So I added some code:
import os, sys
os.chdir("<path_to_dir>")
sys.path.append('<path_to_dir>')
os.system('export PYTHONPATH=<path_to_dir>:$PYTHONPATH')
This code helped to import the module in python shell in interactive mode but launching in terminal is still failing.
So the question is how to make it to work?
I found solution. The SWIG module was compiled incorrectly.
There was option for CMake that suppressed errors for undefined symbols
set(PLATFORM_LIBS "-undefined dynamic_lookup" )
That why the module doesn't contain NSLOG symbol.
The module was recompiled with additional
"-framework Foundation"
in swig_link_libraries statement. And now the module is imported correctly

GetTimeKeeper() is not defined

I am getting the error
timeKeeper1 = GetTimeKeeper()
Error: name 'GetTimeKeeper' is not defined
My code is as follows:
from paraview.simple import *
timeKeeper1 = GetTimeKeeper()
When I run the py script in paraview, it works.
I checked the simple.py of my paraview installation, and GetTimeKeeper() does exist.
You should update your paraview installation, look here: Bug#15779

Python import error with Sublime Text 2 with same PYTHONPATH and Python version as terminal

I just installed gdata with pipinstall
while I can import when starting python from the command line:
import gdata.docs.service
I get an
ImportError: No module named docs.service
when I do it with the sublime python build. I realize that on Python.sublime-build I can specify the python version and the PYTHOPATH.
I checkt both and made sure to have both the same as on the command line. I also checked that the folder from where I start the python console does not include gdata. What am I missing?
my PYTHONPATH check:
import os
try:
user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
user_paths = []
print user_paths
and the Python version check:
import sys
print (sys.version)
I also checked that $which python is the same path as the "cmd" value in the sublime build config file.
I finally find the answer.
The named the file gdata.py and this is why the import gdata.docs.service was resolved with the file itself and could obviously not find "docs" in it.

unresolved import in python opencv samples

I am having problem running the opt_flow.py in /opencv/samples/python2.
In /samples/python everything is okay. But in python2, there seems something missing.
The python version: 2.7.3
IDE: pyDev in Eclipse
running opt_flow.py from
https://github.com/jonmarimba/OpenCVMirror/blob/ff81e19a7a12764c657e2765d69ef166065f5e61/opencv/samples/python2/opt_flow.py
Below are from the code snippet:
import cv2, cv2.cv as cv
import video
from common import anorm2, draw_str
from time import clock
...
and there comes errors..
Description Resource Path Location Type
Unresolved import: video optical_flow.py /practice/test line 9 PyDev Problem
Unresolved import: draw_str optical_flow.py /practice/test line 10 PyDev Problem
Unresolved import: anorm2 optical_flow.py /practice/test line 10 PyDev Problem
which I didn't found any related solution to this error, can anyone help?
I had the same problem so here's the answer just to make it clear to others:
The opencv examples import other files in the same folder. The video.py file is in the same place you found the sample you were running. If you copy one of the examples out, you will also need to copy out other files that it imports, including video.py, common.py, and others.

Categories