I need help to troubleshoot the installation of gspread for an GAE app.
On my Windows PC, I have python.exe in C:\python27.
I installed gspread by running its setup.py from its distribution folder as follows:
c:\python27\python.exe setup.py install --home=X
The following folder and files were created in X\lib\python:
request-2.9.1-py2.7.egg (a folder)
easy-install.pth
gspread-0.2.5-py2.7.egg
site.py
Why lib\python? Is this sub-folder hardcoded somewhere?
When I launch my Python interpreter, I can then import gspread. sys.path includes the fully qualified path to X\lib\python\gspread-0.2.5-py2.7.egg. Note it's a path to a file and not a folder.
How does Python know where to locate gspread? I tried looking in C:\python27 for clues but could not find anything related to gspread, not even in the site-packages folder.
Python searches sys.path in order. It is likely that Python is importing gspread using the contents of the egg. Note that if Python finds a match before the gspread egg, it will stop on the first matching entry in sys.path. For example if you have a module named gspread in the current working directory, then Python will not use the egg.
If you want to modify the package, you have many different options. I suggest to first uninstall the current egg. Then place the folder named gspread in site-packages.
An even better alternative is to add the gspread source directory to PYTHONPATH. You can change the PYTHONPATH environment variable by
My Computer -> Properties -> Advanced > Environment Variables
When you defined --home option setuptools is simulating linux Home directory thats why the installation location goes to X:\lib\python.
My guess is this home path is getting added to Python env on the system sorry I don't have windows to test this but there is some info here: https://docs.python.org/2.3/inst/alt-install-windows.html
Related
I can´t import any module in VSCode.
The structure of my project is the next:
6.Python
-.vscode
-settings.json
-Ortiz
-init.py
-puntoentrada.py
-Paquetes
-Prueba1
-init.py
-prob.py
puntoentrada.py looks like this:
puntoentrada.py
Then, this is prob.py
I tried to run this but I have a problem called:
ModuleNotFoundError: No module named 'puntoentrada'
prob.py
Then, this is the directory of Python
Directory
Then, this is the variable environment
PythonPath
Then, this is my Python > Analysis Cache Folder Path in VSCode:
Configure VSCode
This is the same in "Usuario", "Area de trabajo" and "6.Python"
Then, this is my settings.json
settings.json
I only want to execute "prob.py" and the only task is "import puntoentrada", but I cant do it, because puntoentrada according to VSCode "does not exist"
So, what can I do?
This is not a VSCode, but a Python issue. Python looks in serveral places for packages and modules and you can inspect these places via the sys.path. If prob.py is your main script, Python finds all modules that are in the same folder as prob.py. If your script is in a subfolder, you have to tell that to Python:
from subfolder import mymodule
If the module is part of a package in a completely separate path, your best option is to install that package in editable mode:
pip install path/to/mypackage -e
But you have to have a setup.py in that second package.
A quick-and-dirty workaround would be to simply add that separate path to sys.path using the append method.
I have changed my Python version for the operating environment in these places.
On the top right corner, you can choose the Python Version.
On the left bottom corner, you can choose the Python version.
I want to install python, and then some additional modules, to my computer (windows).
I've been told that the best way to install python and packages is to make a folder in your drive somewhere BEFORE installing anything, (ex. 'Python') then pointing all your downloads (using cd in the command line) to this folder so that everything is in once place, and you don't have to go on a wild goose chase to make sure everything you want access to is in your PATH when you go to import modules etc.
Do I have the right idea?
I have had trouble importing modules in the past because they were not in the Path.
Will changing the directory in the command line before typing:
pip install somemodule
cause that module to be saved to where I just changed the directory to?
pip always installs the libraries in a fixed directory, usually in the user folder. You can check this by the command pip show <installed-package-name>
So you can use any package you already installed to get the pip directory. The location might vary based on your python version and env name.
Example: c:\users\<user>\appdata\roaming\python\python37\site-packages
I have several packages in folder Top. The path is set at the command prompt such that each package contains some python files that use other packages' modules.
I have the following files in Top directory: setup.py, MANIFEST, MANIFEST.in, README. I wish to modify the setup files such that the path is set during installation. Does PYTHONPATH set it, and does it need to go into a new file?
The appropriate actions here are
Packages do not mess with PYTHONPATH. Never.
Instead, you write an setup.py entry point to your command line scripts
When the user installs the package using pip install the command line script is automatically added to user's PATH, which is hopefully inside virtualenv
This command line script is generated during the install, so that it points to the PYTHONPATH of virtualenv or system-wide Python installation. The path is hardcoded at the script head, pointing to the current Python interpreter.
More info
https://packaging.python.org/en/latest/distributing/
I am trying to import ZipCodeDatabase in helloworld.py.
helloworld.py exists at /google-app-engine/helloworld
ZipCodeDatabase module exists /usr/local/lib/python/python2.7/dist-packages
PYTHONPATH = /usr/local/lib/python/python2.7/dist-packages;/usr/local/lib/python/
When compiling helloworld I am still getting "ZipCodeDatabase module not found". Why isn't it being picked from the PYTHONPATH?
I highly doubt you've got a module called ZipCodeDatabase. That naming convention is typically reserved for a class that resides within a module. Modules are usually lowercase or lower_snake_case, to represent the file containing the module. I'm assuming you've installed pyzipcode here, but it may be a different module.
# assuming pyzipcode.py in the dist-packages directory
$ python -c 'from pyzipcode import ZipCodeDatabase'
If I'm wrong above, then are you sure you're running the version of python that has the ZipCodeDatabase module installed?
Some troubleshooting steps:
$ which python
$ python --version
$ python -c 'import ZipCodeDatabase'
$ ls -l /usr/local/lib/python2.7/dist-packages/ | grep -i zip
Also, is it really necessary for you to specify the PYTHONPATH line? Typically, the site-packages folder (and by extension I assume the dist-packages folder on Ubuntu) is included in the default PYTHONPATH, along with the current directory of the python module you're using.
How did you install the ZipCodeDatabase? Did you just drop the file in there? Try putting it alongside your helloworld.py file and try importing it then. Also, a full stack trace is useful information here, especially when others are trying to diagnose the problem you're having.
Edit:
Ok, now that I know you're using google app engine (should have been obvious from your use of paths - I'm sorry), it looks like it doesn't use the site-packages or dist-packages to load modules. You should create a sub-directory in your project with the relevant third party libraries, and add that sub-directory to your path. Disclaimer: I've never used GAE so I might be missing the mark with this.
Check out this answer for how to structure your project and add the extra directory to your path from within the application.
I have two python installation. One is installed in default location and other is installed in my home directory. I am using home directory python installation. I am facing problem about pythonpath. When I run sys.path on 2nd python installation it gives me paths for libraries of default python installation
eg.
2nd python is installed in /home/python2.6.1
now when i use sys.path it gives me
/lib/python2.6/lib-old, /lib/python2.6/lib-dynload etc.
instead of
/home/python2.6.1/lib/python2.6/lib-old, /home/python2.6.1/lib/python2.6/lib-dynload
how can I change path for my python installation in home directory
This is because your libraries are installed in /lib or the interpreter has been configured to scan /lib for libraries. You need to recompile Python and give the configure script another prefix for the libraries.
But, this isn't what I would do. I'd install virtualenv and start managing my Python versions that way. This is what I do actually ;) Clean and simple!