What other ways can python look for modules? - python

We have a software called ArcGIS that comes with a python environment, which has a library called arcpy
When you execute the python.exe from that environment, it imports arcpy with no issue.
But I needed to create another python enviroment that contains the same library as this one, but I just couldn't find anything named arcpy in the enviroment's folders
I even copied the whole Lib folder from the original enviroment to the one I'm trying to create, but it still won't import arcpy
I know this is kinda of a shot in the dark, as it is a proprietary library and I can't be sharing much info, but does anyone knows what could it be?
It seems they use Anaconda too

The python (arcpy) install with ArcGIS typicall installs to:
C:\Python27\ArcGIS10.5
Arcpy does not like to be moved, and the library is linked directly with your ArcGIS installation
C:\Program Files (x86)\ArcGIS\Desktop10.5
If you are using ArcGIS Pro rather than Desktop, it installs into Conda environment:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\
This Q&A on GIS Stack Exchange may be of some interest to you - How to set up Python/ArcPy with ArcGIS Pro 1.3

Go inside the environment with arcpy, look for the environment var PYTHON_PATH. and just add that path to the PYTHON_PATH in your new environment.

Related

'reportMissingModuleSource' and 'reportMissingImports' errors for imported modules pandas and alpha_vantage

I'm very new to python and trying one of my first projects. I have installed modules 'pandas' and 'alpha_vantage' and imported them at the top of my code but they show the errors 'reportMissingModuleSource' for pandas and 'reportMissingImports' for alpha_vantage. I installed them in Command prompt and it was successful but it seems python doesn't recognise them or cant find them.
Potentially useful info:
When I first installed python I had to go into my Path settings and create a new Path to python.
I use VSCode
I had issues installing pip I cant remember why because I've been at this for hours.
Python version is 3.10.5 64bit
Pip version is 22.1.2
I am on Windows
I don't know what python files need to go where so they are slightly scattered around my directory.
Do I need to create a Path in my settings to each module, I already have one going to my scripts folder. I am very stuck so any help is appreciated.
Thank you for anyone that helps!

Python not recognising libraries on Windows machine

I have been having a lot of trouble on my work Windows machine. I cannot get any libraries to work on my python. I use Thonny application for my python scripting.
I have tried setting environmental path to my current directory of python. On my PC its :
C:\Users\petrikas.lu\AppData\Local\Programs\Python\Python38-32\Scripts
Most tutorials say that it should be on C:\Python34\Scripts however thats not the case for my PC.
enter image description here
Python directory:
enter image description here
Can someone suggest me what shall I do next? I have tried many things that I have found online but my script wont compile. I am trying to import pandas library
After running a command:
python -m pip install pandas
It does not return any result. Most certainly did not generate a pandas library in my libs python folder
I would recommend setting up a Conda environment (using Anaconda or Miniconda) for your Windows machine. It's much easier to manage different environments which contain different sets of libraries.

How do my python files get access to installed libraries (Pip)

Sorry in advance if this question has been asked before,
So after some time, I wanted to start a new python project. My previous computer (on which my python files were) died. I had saved my projects in my Dropbox. Now I installed python (3.8, there is also an anaconda installation, but it should not interfere with the python installation) on my new PC, and I cannot import any library to those files.
The python shell can find the imported packages (imported using pip), but even when I move the files to C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts (single user installation). It doesn't work.
I have tried uninstalling and re-installing pygame (in this example. Any library is unusable) using pip, pip3 and even pip3.8, I have added the .whl file by hand, it all didn't work. I have tried a virtual environment, but I can't get that to work either.
I run Windows 10 on a 64-bit computer.
first be sure you know which python installation you use with which import files etc.
you can copy your files not in scripts, but in lib somewhere in site-packages dir.
add your scripts to the python path! sys.path.add(.....) Otherwise python is blind and can't see them

Numpy cannot be accessed on Jupyter. Is it a problem with the path and how do I fix that?

This is probably a very basic question but I have not been able to solve it for some time.
My goal is to start using Python with Jupyter Notebook for data analytics.
I first downloaded Python 3.7 on OSx10.95. Then tried to download Anaconda, which failed a few times. Then I downloaded Miniconda and used Wing101. After that I could download Anaconda. However, I did not get Anaconda navigator to work.
Then I started using Jupyter Notebook from terminal. It works but there are a number of problems:
In Jupyter when I try to import pandas and numpy I get an error:
--------
<ipython-input-1-baf368f80de7> in <module>
----> 1 import pandas as pd
2 import numpy as np
~/anaconda3/lib/python3.7/site-packages/pandas/__init__.py in <module>
17 if missing_dependencies:
18 raise ImportError(
---> 19 "Missing required dependencies{0}".format(missing_dependencies))
20 del hard_dependencies, dependency, missing_dependencies
21
ImportError: Missing required dependencies ['numpy']
----------
Numpy is installed though, but it is probably in the wrong place.
Another problem is that the Anaconda and Python files are all over my computer:
The Anaconda navigator is at:
/anaconda3
Pip 3.7 is at:
/Library/Frameworks/Python.framework/Versions/3.7/bin/
Numpy is at:
/Users/lsluyser/Downloads/ENTER/lib/python3.7/site-packages/pandas/compat/
Jupyter files are at:
/Users/lsluyser/Downloads/ENTER/lib/python3.7/site-packages/
and also at:
/anaconda3/lib/python3.7/site-packages
My question is:
What is the desired organization of the program files and how do I achieve this?
Should I move all files from Downloads to another folder?
Should numpy be put under /anaconda3/lib/python3.7/site-packages?
Can the fact that Anaconda navigator does not work have to do with its location?
Thank you very much in advance!
I suggest using Miniconda, which is a smaller alternative to Anaconda. Even if you don't, you should download the packages you need, such as numpy, from
Anaconda Cloud, which should put the files in proper location.
Generally [on Windows] the packages should be in folder C:\Users\<>\Miniconda3\Lib\site-packages and verify the environment variable has necessary paths.
If you're going to work in Python, you will soon realize the need for creating multiple python virtual environments on your computer.
This is because, when working in Python:
You will constantly run into situations that require you to install, upgrade, or downgrade some new module.
Each such install, upgrade, or downgrade could have some unwanted side-effect (something that was working earlier, stops working after the change).
By creating multiple virtual environments, you will be able to perform such installs, upgrades or downgrades within a specific environment, with no risk of affecting your other environments.
Tools such as Anaconda and Miniconda make it easy for you to create and manage such virtual environments.
Under the hood, the creation and management of the virtual environments is probably not much more than setting some environment variables.
I found this to be a good intro to the concept.
For your problem, yes, most likely your problem with numpy can be solved by suitably setting environment variables, but I would suggest not to attempt that.
Instead, use Anaconda or Miniconda to create an environment, and within that environment, use Anaconda or Miniconda to install numpy. You will of course will be prompted about any pre-requisites that may be needed for numpy.

Installing python with python win32 extensions on a network drive

I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the network, but when importing win32com I get a pop-up error saying:
The procedure entry point ?PyWinObject_AsHANDLE##YAHPAU_object##PAPAXH#Z could not be located in the dynamic link library pywintypes24.dll
after dismissing the message dialog I get in the console:
ImportError: DLL load failed: The specified procedure could not be found.
I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" .
What am I missing and is there another way in which I can install Python + Python-Win32 + additional module once and have them running on many machines? I don't have access to the Microsoft systems management tools, so I need to be a bit more low-tech than that.
On every machine you have to basically run following pywin32_postinstall.py -install once. Assuming your python installation on the network is N:\Python26, run following command on every client:
N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install
Another important thing is Good Luck!. The reason is that you might need to do this as admin. In my case such setup worked for all but one computer. I still did not figure out why.
Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.
So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 to \server\share\python26).
Or, you can add the following code to your scripts before they try to import win32api etc:
# Add Python installation directory to the path,
# because on Windows 7 the pywin32 installer fails to copy
# the required DLLs to the %WINDIR%\System32 directory and
# copies them to the Python installation directory instead.
# Fortunately, in Python it is possible to modify the PATH
# before loading the DLLs.
os.environ["PATH"] = sys.prefix + ";" + os.environ.get("PATH")
import win32gui
import win32con
You could use batch files running at boot to
Mount the network share (net use \\server\share)
Copy the Python and packages installers from the network share to a local folder
Check version of the msi installer against the installed version
If different, uninstall Python and all version dependent packages
Reinstall all packages
This would be pretty much a roll your own central management system for that software.

Categories

Resources