Working backwards from Python namespace to package - python-3.x

I'm working from someone else's code, and they're using openCV, therefore they used "import cv2". I didn't have it installed in my environment at the time so I needed to install that module. Having moved from MATLAB I'm still remembering different packages, but I remembered cv2 is openCV. However, had I not known cv2 was openCV, is there a programmatic way I can find out the package name from the import? i.e: using cv2, and not having openCV installed, finding out what cv2 is?

Related

plotnine: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail

I am trying to use plotnine to generate some graphs. I import the required libraries:
from plotnine import *
from plotnine.data import mpg
And then, if I run the following code in PyCharm I get a Warning message, the window plot
shows a "No answer" message and I am forced to restart the python terminal:
(ggplot(mpg) # defining what data to use
+ aes(x='class') # defining what variable to use
+ geom_bar(size=20) # defining the type of plot to use
)
<ggplot: (150517199824)>
C:\Users\alvaromc317\miniconda3\envs\general\lib\site-packages\plotnine\ggplot.py:363: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
However, If I start a python terminal from windows cmd terminal and run the same script as before, I get no error message and I see the plot with no problem.
What is happening and how do I get to use plotnine in pycharm?
In case it is needed, I work using a Windows 10 machine and python 3x based on miniconda.
I'm having a similar problem, but on MacOS using the commercial addition of PyCharm.
From this github issue and this JetBrains issue, it looks like it might be related to a PyCharm bug.

I have tried many methods and I couldn't find solution. So how to convert Python file to executables?

Python : 3.5
PYinstaller : 3.5
Win64
cx_Freeze : 6.0
According to the above information, I have tried to convert Python project to exe but it does not work.
First I have tried pyinstaller but the process throw some error:
After that, I have tried cx_Freeze and it works, but the exe are working on some computer but not on every computer that have same platform.
I don't know what I can do. I looked for google and stackoverflow but there are unsolved problems or I couldn't see the solution.
Later I have tried to change python version but doesn't work again. Computers that have tried to running the exe, have same OS platform, I'm sure.
By the way, if you receive the following cx_Freeze error, resolving like this:
Build\exe.win-amd64-3.7\lib\scipy\spatial\cKDTree.cp37-win_amd64
change to
Build\exe.win-amd64-3.7\lib\scipy\spatial\ckdtree.cp37-win_amd64
Program uses the following modules : tkinter, pydicom, skimage, PIL, cv2, etc.
Primarily Program has 2 page that content code but I made single file for I came across this sentence "It's worth noting that pyinstaller can compile to a single .exe file"
What do you suggest I do? Thanks for your help.
Edit: I have been tried "Auto-py-to-exe" but I got an error (Fatal Error : Failed to execute script")
Edit2: I tried to run outside the anaconda. I think its work. But I'm still testing.
Edit3: I have tried to change python version, GUI was opened another computer but the program is not work properly. the program works on my computer but not on another computers
If you are not able to convert python file to executable format, you can try using auto py-to-exe library.
This library contains a GUI format to convert .py files to .exe
Here you can find auto py-to-exe with usage instructions,
https://pypi.org/project/auto-py-to-exe/

Pyside to build PyQT designer 4 UI file always results in error

Using Pyside-uic -o pythonfilename.py uifilename.ui to convert my PyQT4 designer GUI to python code. Seems to build just fine with no errors, but when I run the file, it consistently crashes, with type errors I can't solve.
First error gave me trouble because I set a "max size". When I removed the max size, the error changed to be a problem with the palette. I removed the palette settings, and replaced it with style sheets, and now it's giving me the error:
"TypeError: QWidget.setFont(QFont): argument 1 has unexpected type 'PySide.QtGui.QFont'"
I doubt there are this many problems with using Pyside to build PyQT UI files(because it seems to be a pretty standard way of doing it), so that leaves me to believe it's something i'm doing.
**Just a note with a bit more info.
This is software we've been using for some time, and the existing UI was built using this exact method. I inherited the file, and was asked to update the UI, and left with instructions on how to do it. I updated the existing ui file, saved it out, and ran the "Using Pyside-uic -o pythonfilename.py uifilename.ui" command. No errors from the build, but %100 of the time i've tried using this method, it has failed.
I tried googling the answer for hours, and proposed the question to other people.
I solved the issue. After pyside spits out the new python file (built from the UI file), theres a line of code at the beginning that will say something along the lines of "from PySide import QtCore, QtGui"
"PySide" has to be changed to "PyQt4".

Can a python module be imported without installing

Is this possible that a module is imported without installing the same. If no then why is my spyder IDE is showing a warning on the line where it is written import nltk even when nltk is not installed
Spyder runs a static analysis on the code you have in the Editor to offer hints and errors about it.
Since the analysis is static, it means Spyder doesn't run your code to perform it. In your case it simply detects that you have a line like
import nltk
but that there's no other use or call to nltk (for example, with a code like nltk.pos_tag(tokens) or something like that).

is there a way to install the nodebox English linguistics library through pip install?

The NodeBox English linguistic library for Python has some nice features, like conjugation, that could be very useful for a project.
I tried installing through pip in a particular virtualenv, but pip search nodebox only brings up:
NodeBox - Simple application for creating 2-dimensional
graphics and animation using Python code
nodebox-color - Color classes for python
NodeBox-for-OpenGL - 2D animation with Python code
nodebox-opengl - NodeBox for OpenGL is a free, cross-platform
library for generating 2D animations with Python
programming code.
Is it pip-installable (in a virtualenv) by another name maybe? Or is the only way to install to
Put the en library folder in the same folder as your script so NodeBox
can find the library. You can also put it in ~/Library/Application
Support/NodeBox/. It takes some time to load all the data the first
time.
as stated on their website?
The Nodebox library has been succeeded by pattern, which is on the PyPI. The NLP functionality is contained in the pattern.en module. It can be installed with:
pip install pattern

Resources