Adding Path in GIT for KIVY - python

Create a file named 'py.ini' and place it either in your users application data directory, or in 'C:\Windows'. It will contain the path used to start Kivy.
I put my Kivy installation at 'C:\utils\kivy'
so my copy says:
[commands]
kivy="c:\utils\kivy\kivy.bat"
(You could also add commands to start other script interpreters, such as jython or IronPython.)
so my question is:
What commands are supposed to be used in GIT to add this path into a variable "kivy".
Or is it even suppose to be a variable?
And in GIT, to get the script working, it uses "source /c/.../Kivy-1.8.0-py2.7-win32/kivyenv.sh"
But, on to add path, they said to use "C:...\kivy.bat
Why does " /c/" change to "C:"
and why is it 'kivy.ba't not 'kivyenv.sh'
Thank you.

This value is not typically something you would include in a git repo because it is specific to your system. Other people using your repo may have Kivy installed somewhere else, or be on an entirely different OS where that path does not exist.

Related

Importing modules from other folders: how to display function arguments in Spyder or PyCharm?

There are loads of answers on how to import modules from other folders.
The answer always seems to be along the lines of:
import sys
sys.path.insert(0,"c://UserName//MyFolder//MyBeautifulCode")
import myscript as ms
after which you can run ms.my_fun(x,y,z) where my_fun() is defined in c://UserName//MyFolder//MyBeautifulCode//myscript.py
The code runs; however, what doesn't work is that, this way, I do not get the usual tooltip showing the arguments of my_fun(); if instead I copy myscript.py in the very same folder as the script I am currently running, then, yes, I do get the tooltip.
What I mean is I don't see something like this:
I have tried with both PyCharm and Spyder and the behaviour, in this respect, is the same for both.
I suppose this happens because c://UserName//MyFolder//MyBeautifulCode//myscript.py gets added to the path only when the script is run so, before it is run, the IDE doesn't find my_fun()
Is this correct?
If so, is the only solution to manually add c://UserName//MyFolder//MyBeautifulCode//myscript.py to the path ?
By the way, I am talking about a couple of functions which I reuse in 3 separate programs I am running. It is nothing worth publishing on github or pip as a package or anything like that.
For PyCharm, you need to set up your project's venv settings to include that path as well. It took me a lot of time to find it at first - and I used google to search for this! but apparently PyCharm hid the option deeper... well, see for yourself.
Go to the Settings, Project: [your project name here], Python Interpreter
See the cog on the right? Click it, "Show all". This will show up, listing all venvs that PyCharm can use for your project:
With your venv selected, click the last icon at the bottom. The icon looks kinda like a folder structure.
Now we see all the paths recognised by the selected interpreter in PyCharm. We can click + to add a new path. Manually added path will have "(added by user)` at the end, just like in the pic.
If you insert a path into the Python path in your code, it's only interpreted at runtime. To get your IDE to know about your library, you will have to add it to the Python Path, e.g. like described in this question: https://stackoverflow.com/a/55209725/5660315.

Migrating from PyCharm to VS Code: setting paths

I want to switch over to VS Code. I did the following to enable python with the packages I typically use, including a local utilities package on this machine:
Searched for the setting python.pythonPath and made it PycharmProjects/Project/venv/Scripts/python.exe for both this workspace and for my user
Changed my Windows user PYTHONPATH to PycharmProjects/Project/venv/Scripts/python.exe
Tried PycharmProjects/python.exe;local-utilities-directory
However, the folder I'm trying to manually set won't show up as a possible option when I click on my interpreter in the bottom right. Instead I'm defaulting to an older interpreter that doesn't have all the packages I've amassed.
While I can access some packages, while trying to pull in my personal utilities library, pip fails (the term pip is not recognized...)
I see that there are a few other ways to change the python path, however, to my understanding, whether you do it in a .json or via the IDE UI, shouldn't actually matter.
Any help would be appreciated.
So, I think I messed things up by offering too many paths.
I had to double check that the exact same path showed up first in:
Work setting pythonPath
User setting pythonPath
Windows profile path
Windows profile PYTHONPATH
I deleted the other "backup" paths, and it ended up working.

How Do I Permanently Append To Python's sys.path

I'm trying to import some of my own modules on my mac and I can't figure out how to add the path to my modules. I have tried editing the PYTHONPATH environment variable, (export PYTHONPATH="${PYTHONPATH}:/path/to/modules) appending the path to sys.path, etc. Nothing seems to work for me. I want the path to be in sys.path permanently so that I don't need to keep putting import sys then sys.path.append("/path/to/modules") at the top of every document that I make. Is there a file somewhere that contains the path that I could edit? Or do I need to enter a command into terminal or something? Any help is appreciated.
If you want to "install" modules, yes, create a site package. If you just doing something locally, for fun / education on you own computer, modify PYTHONPATH.
On a Mac, you're most likely using bash as your shell.
PYTHONPATH=/path/to/modules:${PYTHONPATH}
export PYTHONPATH
...will do what you want in your current shell. To make it permanent (for you), add both lines to your local .bashrc file, under your home directory.
If you want to make it permanent for all users of this computer.. don't edit the systemwide /etc/profile -- that's when you really should install it correctly using packages.

What is the purpose of the environmental variable PYTHONPATH

On windows 7, I currently don't have a python path. Can I safely make one? If so, how do I do it?
Upon making this variable, I can no longer load Spyder (IDE) without it crashing. Does anyone know why?
I would like to edit my existing python path if possible, but just don't know why it isn't already there in environmental variables.
I would ultimately like to be able to run "python myscript.py" and have myscript be in a different directory from the call directory.
PYTHONPATH adds new paths to the ones Python uses by default. The path in total determines where Python will look for modules when you import them.
Look at sys.path to see the combination of the defaults with your PYTHONPATH environment variable. It's likely that Spyder is loading a module that exists in two different places and the wrong one comes first.
When you import modules in python, python searches for the module in the directories in PYTHONPATH, in addition to some other directories.
In order to be able to run your script as > myscript.py, you want to put your script somewhere on PATH (here are some instructions for viewing or updating PATH), this is where the OS looks for scripts and programs when you give it a command. I believe that in windows the .py extension must be associated with python for windows to know that myscript.py should be run using python. This should happen automatically when python in installed, but maybe someone with more windows knowledge can comment on this.
it has role similar to path. this variable tells the python interpreter where to
locate the module files imported into a program. it should include the python source library directory and the directories contain in python source code

Setting python path

I have a Django app and I'm getting an error whenever I try to run my code:
Error: No module named django_openid
Let me step back a bit and tell you how I came about this:
I formatted my computer and completely re-installed everything -- including virtualenv, and all dependent packages (in addition to Django) required for my project based on settings in my requirements.txt folder
I tried doing python manage.py syncdb and got the error
I googled the issue, and many people say it could be a path problem.
I'm confused as to how I go about changing the path variables though, and what exactly they mean. I found some documentation, but being somewhat of a hack-ish noob, it kind of goes over my head.
So my questions are:
What exactly is their purpose -- and are they on a system based level based on the version of Python or are they project dependent?
How can I see what mine are set to currently?
How can I change them (ie. where is this .profile file they talk of and can I just use a text editor)
Any input you would have would be great as this one is stumping me and I just want to get back to writing code :-)
The path is just the locations in your filesystem in which python will search for the modules you are trying to import. For example, when you run import somemodule, Python will perform a search for somemodule in all the locations contained in the path (sys.path variable).
You should check the path attribute in sys module:
import sys
print sys.path
It is just a regular list, sou you could append/remove elements from it:
sys.path.append('/path/to/some/module/folder/')
If you want to change your path for every python session you start, you should create a file to be loaded at startup, doing so:
Create a PYTHONSTARTUP environment variable and setting it to your startup file. E.g.: PYTHONSTARTUP=/home/user/.pythonrc (in a unix shell);
Edit the startup file so it contains the commands you want to be auto-executed when python is loaded;
An example of a .pythonrc could be:
import sys
sys.path.append('/path/to/some/folder/')
Do you really need to alter the path? It's always best to actually think about your reasons first. If you're only going to be running a single application on the server or you just don't care about polluting the system packages directory with potentially unnecessary packages, then put everything in the main system site-packages or dist-packages directory. Otherwise, use virtualenv.
The system-level package directory is always on the path. Virtualenv will add its site-packages directory to the path when activated, and Django will add the project directory to the path when activated. There shouldn't be a need to add anything else to the path, and really it's something you should never really have to worry about in practice.

Categories

Resources