How to install splunkclient for Windows - python-3.x

I am trying to connect to my splunk server via Python on my WIndows laptop.
I downloaded splunklib and splunk-sdk. However, when I run
import splunklib.client as client
I get an error of
ModuleNotFoundError: No module named 'splunklib.client'; 'splunklib' is not a package
Any ideas on why this is occurring and suggestions on to how to fix this or the best way to access Splunk via Python?

Did you properly install the splunk-sdk? You would normally use something like pip to install it.
pip install splunk-sdk
Alternatively, you can install it into the PYTHONPATH
Refer to
https://dev.splunk.com/enterprise/docs/python/sdk-python/gettingstartedpython/installsdkpython/

Windows requires a manual setup of the SDK.
Download the Splunk Software Development Kit for Python as a zip file.
Unzip the zip file into the same directory as your program source.
Add the following line to your source code before import splunklib.client as client:
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "splunk-sdk-python-master"))
Another option is to unzip the sdk to another folder and specify the absolute path in the sys.path.insert().

Related

Running Streamlit based app as a package (

Apologies is this question is not clear enough - let me know and I can provide further details.
I've packaged up a Streamlit based app for a personal project. I've successfully deployed it on TestPyPi. I can install the package on a new environment/ machine - however am unsure how to actually 'run' (or launch) it there?
All of the pre-reqs are installing correctly using the following....
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple interactive-charts-testJan2022b
However once installed if I use >>> from interactive_charts import run_me (which is a .py file that contains the following:)
import sys
from streamlit import cli as stcli
sys.argv = ["streamlit", "run", "basic_app_4.py"]
sys.exit(stcli.main())
The following is returned...
Usage: streamlit run [OPTIONS] TARGET [ARGS]...
Error: Invalid value: File does not exist: basic_app_4.py
Incidentally, I've included a hello_world.py file, which simply prints "Hello world". This works expected i.e. from interactive_charts import hello_world
I guess this is something to do with the relative path of where the package is installed locally i.e. where thebasioc_app_4.py is physically located; and how that's represented in the sys.argv variable? (as when I navigate to where hello_world.py is located in the terminal and then execute the command it works correctly.
I'm just not sure how I can tell it to use the physical location of the installed folder on the local users' machine?
Any ideas or work arounds would be gratefully received.
Any and all suggestions are welcome. TIA

Trying to set up python for Azure on a Mac using vscode but getting `Import "azure.common.credentials" could not be resolved`

I am new to Python and Azure scripting...and Mac (somewhat). I am trying to create a simple python script so I can create a set of Azure resources I use in a project. I followed these directions to set up vscode and I loosely followed these directions to get started with the Azure commands. Loosely, so I could ensure I knew what was happening. I did not pull down the repo. I am getting an Import "azure.common.credentials" could not be resolved error on the following line:
from azure.common.credentials import ServicePrincipalCredentials
In setting up the vscode/python environment, I selected the 3.7.3 interpreter. I did not pull down the github repo or run the pip install -r requirements.txt, again just to make sure I could do this from scratch and understand how these things work together.
When I run pip install azure from the command line it seems to default to the python 2.7 installation on the Mac, which is deprecated but I think required on the Mac.
Do I need to do the pip install azure for 3.7.3? If so how do I do that?

Webjobs Running Error (3587fd: ERR ) from zipfile

I have the following small script in a file named fgh.py which I have been attempting to schedule as a webjob
import pandas as pd
df=pd.DataFrame({'a':[1,2,2],'b':[5,6,9]})
df['x']=df.a.sub(df.b)
print(df)
Using #Peter Pan post. I have created a virtual environment, done a pip install pandas. From the virtual environment, the script runs and executes as required.It however does not execute when loaded in Azure Webjobs. I suspect issues arise from the interface between the run,bat file and the Azure python console but have limited understanding of Azure to resolve the issue
In kudus, I have used this post to install python.
Running where python in cmd command in https://myapp.scm.azurewebsites.net/DebugConsole I get;
Additionally from https://arcgistrial.scm.azurewebsites.net/DebugConsole I get the following when I run cmd command python -V
In my run.bat file, I have tried to use either of the directories above without success.
Whether I make my run.bat file D:\home\python364x64\python.exe fgh.py or D:python364x64\python.exe fgh.py I get the following error;
I have gone a head and installed pandas and checked if successful by trying to install numpy
All this has not helped. I have been on this for a couple of days and it has to work somehow. Any help?
(Things are not quite straightforward in old Webjobs to run python task with dependencies. It has been quite some time, the world has moved on to Azure Function :))
However, since you still need to stick to Webjobs, below are the steps I followed which worked. I am using a batch file (.cmd) to run the python script due to the pre-requisites.
By default webjob supports python 2.7 at this moment. So, add python3 from 'extension' in your web app, In this case it was 3.6.4 x64 for me. This will add in path D:\home\python364x64\. How did I know? Kudus console :)
Create a requirements.txt file which contains pandas and numpy (note I had to explicitly add numpy version 1.19.3 due to an issue with latest 1.19.4 in Windows host at the time of this writing). Basically I used your fgh.py which depends on pandas which in turn depends on numpy.
pandas==1.1.4
numpy==1.19.3
Create a run.cmd file having the following content. Note 1st line is not needed. I was just checking python version.
D:\home\python364x64\python --version
D:\home\python364x64\python -m pip install --user --upgrade pip
D:\home\python364x64\python -m pip install --user certifi
D:\home\python364x64\python -m pip install --user virtualenv
D:\home\python364x64\python -m virtualenv .venv
.venv\Scripts\pip install -r requirements.txt
.venv\Scripts\python fgh.py
Zip fgh.py, run.bat and the requirements.txt files into a single zip. Below is the content of my zip.
Upload the zip for the webjob.
Run the job :)
Ignore the error "ModuleNotFoundError: No module named 'certifi'", not needed.
The key to solving the problem is that you need to create your venv environment on azure.
Step 1. Run successfully in local.
Step 2. Compress your webjob file.
Step 3. Upload webjob zip file.
Because the test environment has python1 before, I will create a webjob of python2 later.
Step 4. Log in kudu.
① cd ..
② find Python34, click it.
③ python -m venv D:\home\site\wwwroot\App_Data\jobs\continuous\python2\myenv
④ Find myenv folder.
⑤ active myenv, input .\activate.bat.
D:\home\site\wwwroot\App_Data\jobs\continuous\python2\myenv\Scripts>.\activate.bat
⑥ Back to python2 folder, and input pip install pandas.
⑦ Then input python aa.py.

nltk for python 3.6 in windows64

I'm new to python, I'm using Windows 10 and have python36 and I basically have to use nltk for my project and i basically have two questions.
1 I heard pip is automatically downloaded for versions 3+ but when I type pip install nltk in command prompt im getting the following error even though i added its path "C:\Users\dheeraj\AppData\Local\Programs\Python\Python36\Scripts\pip36" in advanced settings and ya in above path i tried pip36 and pip in both cases result is same.
'pip' is not recognized as an internal or external command,"
2 In www.nltk.org I found nltk for mac, unix and windows32 but not for windows64 ,does that mean it doesnt support for 64bit or is there any way for me to install nltk.
I had the same problem as you, but I accidentally found pip.exe in my python directory, so I navigated to said directory with CMD and ran the command pip install -U nltk and it worked.
Run the Python interpreter and type the commands:
import nltk>>>
nltk.download()>>>
A new window should open, showing the NLTK Downloader. Click on the File menu and select Change Download Directory. For central installation, set this to C:\nltk_data (Windows), /usr/local/share/nltk_data(Mac), or /usr/share/nltk_data (Unix). Next, select the packages or collections you want to download.
If you did not install the data to one of the above central locations, you will need to set the NLTK_DATA environment variable to specify the location of the data. (On a Windows machine, right click on “My Computer” then select Properties > Advanced > Environment Variables > User Variables > New...)
Test that the data has been installed as follows. (This assumes you downloaded the Brown Corpus):
from nltk.corpus import brown>>>
brown.words()>>>
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]
Installing via a proxy web server
If your web connection uses a proxy server, you should specify the proxy address as follows. In the case of an authenticating proxy, specify a username and password. If the proxy is set to None then this function will attempt to detect the system proxy.
nltk.set_proxy('http://proxy.example.com:3128', ('USERNAME', 'PASSWORD'))>>>
>>> nltk.download()
Command line installation
The downloader will search for an existing nltk_data directory to install NLTK data. If one does not exist it will attempt to create one in a central location (when using an administrator account) or otherwise in the user’s filespace. If necessary, run the download command from an administrator account, or using sudo. The recommended system location is C:\nltk_data (Windows); /usr/local/share/nltk_data (Mac); and/usr/share/nltk_data `(Unix). You can use the -d flag to specify a different location (but if you do this, be sure to set the NLTK_DATA environment variable accordingly).
Run the command python -m nltk.downloader all. To ensure central installation, run the command sudo python -m nltk.downloader -d /usr/local/share/nltk_data all.
Windows: Use the “Run...” option on the Start menu. Windows Vista users need to first turn on this option, using Start -> Properties -> Customize to check the box to activate the “Run...” option.
Following are the steps I followed to resolve this issue:
Click on Python 3.6 Module Docs (32 bit). This will open in your default browser.
Click on pip(Package), displayed at the end of the page.
You will be redirected to a page displaying details of the package. Find the exact path from there. It will be something like c:\users\grove\appdata\local\programs\python\python36-32\lib\site-packages\pip
Run this on cmd prompt.
Once you're in pip folder type pip install -U nltk
Go back to Python Shell and type import nltk
Directly Search for pip folder and navigate throught that path example:
C:\Users\PAVAN\Environments\my_env\Lib\site-packages\pip>
Run cmd
and then run the command
pip install -U nltk
I will recommend you to use the Anaconda on Windows. Anaconda has nltk version for Python 64-bit. Now I'm using Python 3.6.4 64-bit and nltk.
Under python shell run:
import nltk
nltk.download()
then the downloader will be open in new window and you can download what you want.
First install the module
like pip install -U nltk
and the use the import statment in the command prompt or IDLE
import nltk

SIP install - unable to open siplib.sbf

I'm trying to install SIP on my computer so I can proceed to get PyQt. I put the install files in a folder on my desktop ('C:\Users\User\Desktop\Programming\Sip\sip-4.15.5'). So, to install it, I ran the following commands from CMD:
cd C:\Python33
python "C:\Users\User\Desktop\Programming\Sip\sip-4.15.5\configure.py"
The version of python in 'C:\Python33' IS the one used in the command 'python'. Here's the output I got:
This is SIP 4.15.5 for Python 3.3.5 on win32.
The SIP code generator will be installed in C:\Python33.
The sip module will be installed in C:\Python33\Lib\site-packages.
The sip.h header file will be installed in C:\Python33\include.
The default directory to install .sip files in is C:\Python33\sip.
The platform/compiler configuration is win32-msvc2010.
Creating siplib\sip.h...
Creating siplib\siplib.c...
Creating siplib\siplib.sbf...
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
Error: Unable to open
"C:\Users\User\Desktop\Programming\Sip\sip-4.15.5\siplib\siplib.sbf"
Now, the key lines are obviously the last two, so I looked in the appropriate folder and found that there was a rather good reason for the error: there is no "siplib.sbf." The closest it gets is "siplib.sbf.in". What on earth is going on? If this is a stupid question, please feel free to tell me so.
You must change current working directory to the sip-4.15.5 first:
cd C:\Users\User\Desktop\Programming\Sip\sip-4.15.5
python configure.py

Resources