I'm playing around with the Unreal Engine 4 and the python plugin. Adding it and getting it to work is no problem (win64, python 3.6.5 64bit) but since almost every py file for unreal starts out with import unreal_engine and I don't have that installed to the system like I would with something from pip install I'm wondering where to put what part of that repo so I don't have the pylint error [pylint] E0401:Unable to import 'unreal_engine' and lots of other "errors" like the following:
class Hero:
# this is called on game start
def begin_play(self):
self.startZ = self.uobject.get_actor_location().z
the last line with self. presents a linter error of [pylint] E1101:Instance of 'Hero' has no 'uobject' member.
Again I want to stress that all the code works inside of Unreal but it would be really nice to have the IDE pick the classes up right so I also get the autocomplete suggestions for available methods on uobject.something.
I'm fairly new to python programming and only ever had to import system libraries or things installed via pip so this is confusing to me.
For reference I have installed python via the official python installer for Windows to c:\dev\Python\Python36. The bin folder is in windows PATH and all that fun stuff.
Related
I'm pretty new to python and would like to have autocompletion using vs code inside my project.
For external modules it works fine but I dont get autocompletion for my own files/modules.
For example, I have a main.py file inside my src folder and a roboter.py next to it.
I import a Roboter class via from roboter import Roboter and it runs fine but I dont get any autocompletion on it.
Also, I'm using no virtual env but have all other packages global on which I do get autocompletion.
What am I missing here?
Okay, installing a 64 bit version of python instead of a 32 bit version did the job.
I just started learning to customize my foorprint in Kicad via python scripts. I got stuck on “import pcbnew” because it gave me the error “no module name pcbnew” all the time. I checked my Kicad folder and found all the py examples for script foorprint wizard, but there’s no file named “pcbnew.py”.
I’m wondering if it’s because I’m using python3.5 rather than python2.7 and how can I fix this problem. Should I download the pcbnew script from somewhere like Kicad Github (I searched a lot but didn’t find any really helpful solutions…)? Or should I re-install my Kicad or python? My Kicad version is 5.0.
Thanks a lot!
Kicad includes it own version of Python (Version 2.7.13 at time of writing for Kicad 5.1 but moving to python 3 shortly). You can access Kicad python via the Pcbnew python terminal Tools > Scripting console.
If you wish to run a script you have a couple of options.
Run it using the inbuilt python 2.7 using either the scripting console or specifying the Kicad python version in the shebang line (you will have to search for this but, in macOS, for instance it is found in /Applications/Kicad/kicad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python)
Import the kicad site-packages into the python environment you are using.
import sys
sys.path.insert(0,"/Applications/Kicad/kicad.app/Contents/Frameworks/python/site-packages/")
import pcbnew
I'm trying to set up a roguelike Python project, but I can't seem to be able to import libtcod module into my project. This helloworld crashes, and the IDE keeps telling me that there is no module named libtcodpy.
import libtcodpy
def main():
print('Hello World!')
if __name__ == '__main__':
main()
What is the proper way to import modules into Python projects? I'm used to Java, so I was expecting something along the lines of Maven to manage the dependencies. There indeed seems to be something like that in PyCharm as well, this package manager for the venv, which from what I gather serves to isolate the project-specific stuff from the OS- or python-global stuff:
but libtcod simply isn't present in the rather exhaustive list of modules that appears after clicking on the "+" button, just some other module that has something to do with libtcod library (I guess?). Moreover, all the tutorials I found on setting libtcod up advise one to manually copy over files somewhere or run some command that I suppose does the importing somehow and other such solutions, all of which i tried and none of which worked. I don't want to pollute my project structure by using such hodgepodge ways of handling dependencies if I can at all avoid it.
Q: How do I get libtcod to work in my PyCharm project in the most clean and convention-abiding way possible?
Take a look at this github project called tcod: https://github.com/libtcod/python-tcod/blob/master/README.rst#installation
It's a python port of libtcod.
To install using pip, use the following command:
python -m pip install tcod
If you get the error "ImportError: DLL load failed: The specified module could not be found." when trying to import tcod/tdl then you may need the latest Microsoft Visual C runtime.
Blockquote
I am relatively new to programming and posting to Stack Overflow. Please forgive my ignorance.
I am attempting to use a third party module in a program of my own, however I can't work out how to access the module within my Python script.
Mac OS X Sierra 10.12.4
Python 3.6.1
Anaconda 4.3.1
Specifically, I would like to be able to access anki (https://github.com/dae/anki).
I initially tried the line:
from anki import Collection
That resulted in a 'ModuleNotFoundError'.
Next I tried:
conda install anki
which also didn't work and yielded a 'PackageNotFoundError'
After more searching, I decided to try:
import sys
sys.path.append('usr/share/anki')
from anki import Collection
However, this also results in a 'ModuleNotFoundError'
What do I need to do to be able to access this module?
I am sure that it is possible because I have come across several other programs which make use of it:
-https://eshapard.github.io/anki/open-the-anki-database-from-python.html
I recognize that the link above purports to offer a solution to exactly this problem, however the solution proffered isn't working for me. Thanks in advance.
You are telling about Anki for desktop computers, which IS application written in Python, but it is NOT an installable Python package.
So the commands like
conda install anki
or
pip install anki
have no meaning.
So the only way is to download full source code of this project, unzip the content of it (only) folder into your project (change you actual folder to it) and then you may do import commands.
This is the first time I have attempted to use anything other than what's provided by python.
I have recently gotten into pythons provided Tkinter, though due to some issues I decided to use another GUI, and heard that PyQt was highly recommended, so I downloaded that and looked into various tutorials. In these tutorials, I cannot seem to execute any of the import statements in said tutorials that relate to PyQt, primarily PyQt5 (I have checked I have the correct version number by the way).
So for instance:
import PyQt5
raises the error:
Traceback (most recent call last):
File "/Users/MEBO/PycharmProjects/Music/testing.py", line 1, in <module>
import Qt
ImportError: No module named 'Qt'
[Finished in 0.1s with exit code 1]
I have a lot of research into this. I've heard people talk of using pip to install modules, and I have done this be safe (as well as downloading it from the internet), I've tried changing the project interpreter to versions Python3/ 2.7/ 2.6, appending the path name to the sys.path directory, (which I really know nothing about to be honest, I was hoping I'd get lucky), though nothing seems to work.
Are you supposed to be able to just import a module off the bat, or do you have to set some things up first?
For windows download the package and extract it to (path where python installed)\Python27\Lib and then try to import.
Specific to PyQt
This package cannot just be downloaded and imported, it must be built because it is not pure python, it uses Qt (C++) and requires dependancies. Read this tutorial on installation.
There is also a very complete python package distribution, Anaconda, that includes pyqt and much more. Almost all the packages I ever looked at are in there.
In general to pure python code
In other cases, if you place modules/code that has been download into the directory that your python script is run from, you can import off the bat, or you can append/insert any folder to the sys.path.
# importer will search here last
sys.path.append('/path/to/code/')
# importer will search here second, right after script's directory
# this can be useful to override a module temporarily...
sys.path.insert(1,'/path/to/code/')