I made a small game of pong in python and the idle I used was eclipse and all of it works (for the most part). But when I try to run the game through the python launcher rather than eclipse it crashes immediately. In fact any program that I make in eclipse won't run outside of it. I'm basically trying to figure out how I will be able to put my game on other peoples computers.
What is the problem?
Your description is too generic, but I'll answer as to what is the most likely issue: your environment.
Fundamentally, eclipse does NOT use the pythonpath set in your environment. It has its own internal configuration (python interpreter, pythonpath, etc...).
So make sure your environment variables match your eclipse configuration. That is likely to solve your problem.
Related
I am having a hard time activating virtual environment, after I have created it.
The thing is, that when I try to activate virtual environment in command line, it works -
virtualenvironmentname\Scripts\activate
But when I try to run the same command in Atom, (I am using the Terminus package in order to be able to run the terminal inside Atom) I get this message -
File (path\activate.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.
I was trying to run it by using slightly different commands such as -
activate virtualenvironmentname or activate (virtualenvironmentname)
, but it did not work.
I was further investigating a little more and I have found some clues, that I might need to change some script execution policies, but I am little bit afraid to do so, because I do not want to mess up my computer since I am just a beginner when it comes to system configuration.
Could anybody please tell me, how could I fix this problem? It would be really convenient for me to be able to run the virtual environment from Atom, since I will be writing my Python and Django lines of code there.
Thank You very much and I hope, that my description of the problem was somehow understandable.
I have been developing a Pacman game in python using pygame module, using IDE Pycharm. When setting up my project I went with the default settings in Pycharm and it set up a venv for me. Running the code from my system interpreter makes it run really really slow with the cpu usage being more than 200%, while running with the venv interpreter it works as expected and cpu usage is about 70-80%. My question is why is that and how to fix it.
I have not uploaded my code, because I thought maybe the problem is not with the code, however if you want I will edit the post and upload the code as well.
I'm developing universal tools that work across various CG software packages such as Maya, Houdini, Nuke, etc., and I'm wondering if there's a workflow for merging each software's custom interpreter into a single master interpreter inside a virtual environment?
To elaborate:
I know how create a custom environment for Maya development in PyCharm, but this only works with mayapy.exe as the interpreter. I'd ideally like to use a clean python.exe as my master interpreter, then add packages for each software in order to get completion working.
Here's a gist of the script I've been working with. All it needs is PySide and Qt.py installed into a Python 2.7 venv to run. If I do all the steps from the first link (Maya dev in PyCharm) EXCEPT use mayapy.exe as the interpreter and instead use python.exe I've found that autocompletion actually works, but the script will not execute unless I'm using the mayaypy.exe as the interpreter.
I guess my main problem is I'm not sure if this is even possible. And if it is possible I'm not sure what packages to use or how to find out what packages I need.
You may have to make some mocking (see mock module) or use external interpreters of each application.
You can also clone to your main python site-packages the application's commands in order to have the auto-completation.
If I remember nuke has already a clone for autocompletion but maya is more tricky.
---EDIT---
I remember only for nuke and maya (the ressources for maya is old but might be helpful)
For nuke :
http://www.nukepedia.com/written-tutorials/using-eclipse-with-nuke
http://www.nukepedia.com/python/misc/nukepydummy
https://help.thefoundry.co.uk/nuke/content/comp_environment/configuring_nuke/command_line_operations.html
For maya :
https://www.highend3d.com/maya/downloads/applications/syntax-scripting/c/eclipse-autocompletion-for-maya-python-api
https://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/PyMel/eclipse.html
http://www.toadstorm.com/blog/?p=136
Situation: I've installed a bunch of packages with pip. I've now written code using these packages.
I have a myscript.py
My friend is on windows.
has python installed.
He has no packages.
He cannot get any packages.
He has pip
He will never be able to use the internet to get more packages everything must be hand delivered.
In fact about 10 minutes after he runs whatever I give him, he formats his machine and it's gone.
How do I take myscript.py and give it to him on a USB stick so that he can copy the file myscript.py onto his computer and run it?
I thought Pipenv would do it but it looks like it just creates a LIST of packages to download from the internet. (a very well defined list... but a list not the actual files needed to run something. Do I understand it correctly?
Right now I'm giving him .exe made with py2exe. This isn't very elegant considering he has python already.
tl;dr how do I give a python script .py to an end user that doesn't have the internet?
You can package everything up in a virtual environment and give him the complete environment necessary to run the script. You can read about this at https://developer.mozilla.org/en-US/docs/Python/Virtualenv and an IDE like PyCharm will help you create such an environment easily.
It's actually a good thing to learn about and do anyway.
I have Pydev installed in Eclipse and everything works fine. I can import other modules installed through "pip install xxx" without any warnings or errors.
However, I got such a warning when I created two files to test:
test/HelloWorld.py
def hello():
print('Hello World')
test/HelloWorldTest.py
from HelloWorld import hello
def test():
hello()
I can run this "HelloWorldTest" without problem, which correctly prints "Hello World". However, in my PyDev editor, it always warns that:
hello Found at: test.HelloWorldTest
from HelloWorld import hello
―――――――――――――――――――――――――――――――――――――――――
Unresolved import: hello
Why does it show that 'hello' is unresolved import, which is highlighted in red? However, I can still run it with correct result.
Very strange!
Edited:
Maybe your IDE is pointing to a different Python interpreter.
I do not use Eclipse but it happens with PyCharm as well.
In PyCharm I can select a different Python interpreter for the code editor and a different one for running. Normally I would not select different interpreter for the same project and confuse myself but it is possible for edge cases.
I think similar thing is happening with your Eclipse IDE. Please double check your settings and make sure the code editor is pointing to the right Python interpreter.
If you are working on multiple Python projects, it is highly recommended to use some sort of Python Virtual Environment to avoid dependency conflicts. PyEnv (https://github.com/yyuu/pyenv) is a good one if you are on Linux or Mac.
Im pretty sure the path for the Python interpreter is not set properly on your IDE.
Answer updated
Why does your folder icons look so different? Are they inside a zip folder or something?
It works perfectly fine on my machine. I do not see any errors.
Please check my settings.
Window > Preferences > type python interpreter in the search box. Try removing the interpreter and manually add again.
Right click on the project folder > Properties > type interpreter in the search box.
Hopefully this solves your issue.
Python Virtual Environment
As you are working on many different projects, it is highly recommended to use a Python Virtual Environment if you haven't already. PyEnv (https://github.com/yyuu/pyenv) is a good one if you are on Linux or Mac. Or you can use the default VirtualEnv with VirtualEnvWrapper if you are on Windows.
Quick note on Coding Style
It has nothing to do with your question but I think its worth mentioning.
I highly recommend you to enable PEP8 feature on your IDE because it helps you to make your project and code much more consistent.
It is recommended to have module names in lowercase.
ref = https://www.python.org/dev/peps/pep-0008/#package-and-module-names