Setting up eclipse for maya 2013 - python

I followed this instructions:
http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html
Also have read the Maya's documentation:
http://download.autodesk.com/global/docs/maya2013/en_us/files/Python_Python_from_an_external_interpreter.htm#
And now I can successfully import and initialize Maya Standalone and
Cmds module.
BUT, as I try to code something like 'cmds.polyCube()', first I don't have any
auto completion and secondly Eclipse returns with an error saying that cmds module
Doesn't has any variable that named polyCube() etc....
Here is my exact procedure which I use to import and initialize maya inside Eclipse:
import maya.standalone
maya.standalone.initialize()
import maya
from maya import cmds
cmds.polyCube(n='cuby_01')
cmds.select('cuby_01')

Are you sure you followed this step from the pymel eclipse docs:
Click the “New Folder” button again, and add the site-packages directory you removed earlier. We did this in order to ensure that the
stub maya package is found before the real maya package. When you’re
done, the main site-packages directory should be somewhere below the
extras/completion/py folder you just added.
That is the important part for adding the stubs to your custom interpreter. In the end you should have a mayapy interpreter set up, with this added site-packages location. And also, make sure when you create a new pydev project, that you go into its specific properties and set the python interpreter to the mayapy that you set up. Otherwise you could still possibly be using the default python interp.

I wrote a little explanation here, how to add a mayapay interpreter here:
Eclipse environment for Maya's python modules
I'm pretty sure is this one your problem.
give a look and if you have any question don't hesitate to ask here again :)

You can also take a look at this tutorial:
http://www.creativecrash.com/tutorials/using-eclipse-as-a-maya-ide (the most relevant portion is available on the 'page 2' tab in the linked page). Basically, you need to point Eclipse's 'predefined' at the /devkit/other/pymel/extras/completion/pypredef
Your sample should work correctly as long as (a) you're using a 2.6 interpreter and (b) you've got the maya python directory in your eclipse PYTHONPATH:
Its usually easiest to configure eclipse to use /bin/mayapy.exe as the intepreter for maya. You might find it easier to use
import maya.standalone
maya.standalone.initialize()
import maya.cmds as cmds
pc = cmds.polyCube()
the cmds module imports as empty UNLESS you've already initialized maya.standalone - your sample shows that but perhaps you got that error in an earlier run without standalone.initialize()?

Related

Is it possible to specify the search path for a module in a python script? If it is, how do I do that?

I have been coding in python for about 2 months, but I'm only familiar with basic object-oriented programming, so I do not really understand things like how searching for modules is implemented. (Basically I'm a noob.)
I pip installed a package called Opentrons Opentrons 2.5.2 and all its dependencies into the samefolder as a python script I'm currently writing. However when I tried to import the module below[1], I get an error saying that "Opentrons is not a module". Then, I tried shifting it into the python library because I found out the search path using the pprint module and it seems to work. I was wondering if I can specify the search path from the .py file itself instead of manually printing the search path and putting the file into the library that the script searches for. (Willing to put in images of the directories I put the opentrons package in if it helps.)
[1]
import sys
import pprint
pprint.pprint(search.path)
from opentrons import robot, containers, instruments
Edit: I realise that the fact that I am running all my scripts in a Spyder console located in a python 3.6 environment might be important.
You can try using the __import__ function, or importlib. This should allow you to specify the path.

Python module created with Boost.Python won't be imported

I have a big C++ module with Python 3 bindings using Boost.Python, that I compile to a .so file using CMake on macOS.
When I try to import it in the REPL, everything seems to work fine:
>>>import myModule
>>>
However, as soon as I run the import statement, the famous rocket icon of Python shows up in the Dock and stays there jumping for some minutes and stops after. Obviously then, I cannot access any of the functions defined in my module, so the import looks fine but doesn't actually do anything.
I tried looking in the Console and saw that whenever I import myModule, I get two launchservicesd[83]: SecTaskLoadEntitlements failed error=22.
It brought me to this and that related questions but I can't find what the exact problem is.
The C++ module is huge so I just can't look at the code and find the problem, thus I'm asking for any hints about at least how to debug that problem.
I can suggest the following steps:
Try to import that module though local python session. So, run interactive python interpreter, and 'import myModule'.
If bad, try to check:
are python version, with which myMoudle was linked with, is similiar to used interpreter
check that build architectires are the same
check that you can load even simple boost.python example module
If ok, check that you have correctly set up module search path in your python code.

Python - Where to paste files to import

First of all let me tell you that I'm a new user and I'm just starting to learn Python in College so my apologies if this question is answered in other topic, but I searched and I can't seem to find it.
I received a file work.pyc from my teacher and he says I have to import it in my Wing IDE using the command from work import *, the question is I don't know where to put the file to import it.
It just says ImportError: No module named work.
Thank you
There are several options for this.
The most straightforward is to just place it in the same folder as the py file that wants to import it.
You may also want to have a look at this
if you're using the python interpreter (the one that lets you directly input python code into it and executes) you'll have to do this:
sys.path.append('newpath')
from work import *
where newpath is the path on your filesystem containing your work.pyc file
If you're working on a script called main.py in the folder project, one option is to place it at project/work.pyc
This will make the module importable because it's in the same working directory as your code.
The way Python resolves import statements works like this (simplified):
The Python interpreter you're using (/usr/bin/python2.6 for example, there can be several on your system) has a list of search paths where it looks for importable code. This list is in sys.path and you can look at it by firing up your interpreter and printing it out like this:
>>> import sys
>>> from pprint import pprint
>>> pprint(sys.path)
sys.path usually contains the path to modules from the standard library, additional installed packages (usually in site-packages) and possibly other 3rd party modules.
When you do something like import foo, Python will first look if there is a module called foo.py in the directory your script lives. If not, it will search sys.path and try to import it from there.
As I said, this explanation is a bit simplified. The details are explained in the section about the module search path.
Note 1:
The *.pyc you got handed is compiled Python bytecode. That means it's contents are binary, it contains instructions to be executed by a Python virtual machine as opposed to source code in *.py that you will normally deal with.
Note 2:
The advice your teacher gave you to do from work import * is rather bad advice. It might be ok to do this for testing purposes in the interactive interpreter, but your should never do that in actual code. Instead you should do something like from work import chop, hack
Main reasons:
Namespace pollution. You're likely to import things you don't need but still pollute your global namespace.
Readability. If you ever read someone elses code and wonder where foo came from, just scroll up and look at the imports, and you'll see exactly where it's being imported from. If that person used import *, you can't do that.

no module named menu_pool

i installed django cms correctly but it says no module named menu_pool
do i have to install other menu plugin?
this path from menus.menu_pool import menu_pool i cannot find, what is the problem? can someone please help me find the clue
i followed the django-cms docs as written here: http://docs.django-cms.org/en/2.3/getting_started/tutorial.html#configuration-and-setup
It looks like Python can do import menus just fine, otherwise the error message would be different. A quick search through the docs for menus reveals that you likely want MenuPool instead of your second menu_pool.
If I'm not mistaken, from menus.menu_pool import MenuPool should give you your expected behavior. Then MenuPool will be in your namespace, so you can do nodes = MenuPool.get_nodes(), and anything else you wish.
Not much experience with django but you should check the module files installed on your system itself to see if there is some mistake or not.
You can get the directory address from sys.path variable in python itself.
Most of the time source is installed with python modules, so you can open up those files and see for yourself if this module is really there or not.
Or you can use the dir(menus) to see what modules are there under menus.

Is there any way to get python omnicomplete to work with non-system modules in vim?

The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.
Once I generated ctags for one of my site-packages, it started working for that package -- so I'm guessing that the omnicomplete function depends on ctags for non-sys modules.
EDIT: Not true at all.
Here's the problem -- poor testing on my part -- omnicomplete WAS working for parts of my project, just not most of it.
The issue was that I'm working on a django project, and in order to import django.db, you need to have an environment variable set. Since I couldn't import django.db, any class that inherited from django.db, or any module that imported a class that inherited from django.db wouldn't complete.
I get completion for my own modules in my PYTHONPATH or site-packages. I'm not sure what version of the pythoncomplete.vim script you're using, but you may want to make sure it's the latest.
EDIT: Here's some examples of what I'm seeing on my system...
This file (mymodule.py), I puth in a directory in PYTHONPATH, and then in site-packages. Both times I was able to get the screenshot below.
myvar = 'test'
def myfunction(foo='test'):
pass
class MyClass(object):
pass
Just ran across this on Python reddit tonight: PySmell. Looks like what you're looking for.
PySmell is a python IDE completion helper.
It tries to statically analyze Python source code, without executing it, and generates information about a project’s structure that IDE tools can use.
While it's important to note that you must properly set your PYTHONPATH environmental variable, per the the previous answer, there is a notable bug in Vim which prevents omnicompletion from working when an import fails. As of Vim 7.2.79, this bug hasn't been fixed.
Trouble-shooting tip: verify that the module you are trying to omni-complete can be imported by VIM. I had some syntactically correct Python that VIM didn't like:
:python import {module-name}
Traceback (most recent call last):
File "<string>", line 1, in ?
File "modulename/__init__.py", line 9
class empty_paranthesis():
^
SyntaxError: invalid syntax
Case-in-point, removing the parenthesis from my class definition allowed VIM to import the module, and subsequently OmniComplete on that module started to work.
I think your after the pydiction script. It lets you add your own stuff and site-packages to omni complete.
While your at it, add the following to your python.vim file...
set iskeyword+=.
This will let you auto-complete package functions e.g. if you enter...
os.path.
and then [CTRL][N], you'll get a list of the functions for os.path.

Categories