I have followed tutorial from this site : http://www.nltk.org/howto/twitter.html
Right now my problem is I don't know what are the values in Environment Variables need to be input. I am using Windows 7.
On a Unix-like system (including MacOS), you will set the variable something like this:
export TWITTER="/path/to/your/twitter-files"
Rather than having to give this command each time you start a new session, it's advisable to add it to your shell's configuration file, e.g. to .bashrc.
On a Windows machine, right click on “My Computer” then select Properties > Advanced > Environment Variables > User Variables > New...
I try input the value with path to 'twitter-file'
When I run the code in python-notebook:
from nltk.twitter import Twitter
tw = Twitter()
tw.tweets(keywords='love, hate', limit=10) #sample from the public stream
I got this error :
ValueError: Supply a value to the 'subdir' parameter or set the TWITTER environment variable.
Thank you.
I had the same issue (Under Windows 10.) A little background, to make sure we're on the same page- I'm using Anaconda 2 and running the exact same tutorial you reference in a Jupyter notebook. I set the same user environment variable you did:
environment variable screenshot
At this point I kept coming up with the same ValueError when calling Twitter(). I ran: % env to see exactly what was in my working environment and found that the TWITTER environment variable I had set was missing. I reasoned that Jupyter was pulling the environment variables when the program started.
The Fix- I closed Jupyter and Anaconda 2 (and all related windows.) On restarting Jupyter and again running: % env The TWITTER environment variable was now listed and the examples from the tutorial are returning results:
tw = Twitter()
tw.tweets(keywords='love, hate', limit=10) #sample from the public stream
Tutorial Results screenshot
I apologize for the verbose reply- I hope this helps.
Related
I'm currently trying to set up my Spyder on Anaconda to connect with PLAXIS. However, I'm not sure how to do that and couldn't find a step by step guide online.
I've tried to change the Python interpreter to the python.exe in the Bentley folder but an error says "spyder-kernels not installed". I've tried to create another environment and install this spyder-kernels but when I changed the Python interpreter it still didn't work. My guess is that I have to connect the Bentley python.exe and the spyder-kernels somehow. Can anyone please provide some help? Thanks!
You install Plaxis. Plaxis comes within the installation with a Python Interpreter (usually > v3.8.x). And I assume you also have a python interpreter on your own PC.
From here it can work in two ways:
You use the Python interpreter that comes with Plaxis.
You use your own Python interpreter to connect to Plaxis.
In case nr.1: Make sure you are in your correct working directory for future plaxis scripts. In your IDE, you have to change the Python interpreter to the one that comes with Plaxis, usually found in the C:\ProgramData\Bentley\Geotechnical\PLAXIS Python Distribution V2\python folder. Next you have to connect to the Plaxis API.
Create an empty python file "example.py" in your working directory, then type this:
from plxscripting.easy import *
import subprocess, time
PLAXIS_PATH = r'C:\Program Files\Bentley\Geotechnical\PLAXIS 2D CONNECT Edition V22\\Plaxis2DXInput.exe' # Specify PLAXIS path on server.
PORT_i = 10000 # Define a port number.
PORT_o = 10001
PASSWORD = 'SxDBR<TYKRAX834~' # Define a password (up to user choice).
subprocess.Popen([PLAXIS_PATH, f'--AppServerPassword={PASSWORD}', f'--AppServerPort={PORT_i}'], shell=False) # Start the PLAXIS remote scripting service.
time.sleep(5) # Wait for PLAXIS to boot before sending commands to the scripting service.
# Start the scripting server.
s_i, g_i = new_server('localhost', PORT_i, password=PASSWORD)
s_o, g_o = new_server('localhost', PORT_o, password=PASSWORD)
s_i.new()
g_i.gotostructures()
In case nr.2: You have to go to your Plaxis input program then Expert > Python > Configure Python interpreter > Choose your interpreter and install the required components as you will not be otherwise able to use the plxscripting module. After that is just the same as in case 1.
I'm trying to set pythonpath but when I follow in some example in other stackoverflow, I just get a red message or nothing happened.
In my picture, u can see, no my folder D:\DemoPython
Does anyone have exactly how to set it?, please give me some examples or the exact answer would be better. Thank so much.
The syntax for setting environment variables you found is for cmd.exe (the DOS-like prompt that has shipped with Windows for ages). You're running in PowerShell, which is newer, and has significantly different syntax.
On PowerShell (which you're using), you want:
$env:PYTHONPATH = "D:\DemoPath;${env:PYTHONPATH}"
or
$env:PYTHONPATH = "${env:PYTHONPATH};D:\DemoPath"
depending on whether you want to take precedence over existing entries or not, respectively.
My Computer > Properties > Advanced System Settings > Environment Variables >
Just add the path as
C:\Users\zee\AppData\Local\Programs\Python\Python39 (or wherever you installed python)
I am trying to retrieve the parameters set from the jenkins build into my python script, but am having trouble. I understand the parameters set from here:
Are set as env variables and all I have to do in python is do:
# Env variables
UPDATE_DATA = os.environ.get('update_data')
ALL_BUILDS = os.environ.get('all_builds')
However I am getting None for those values. When I do an echo of those parameters in my jenkins script before my python script runs, I could see them being printed out correctly. However, for some reason python does not see them. If I go manually into a terminal and export a variable and run my python script, it works.. So I'm completely lost here.
Jenkins server is running on linux. Using python 2.7
You can use the boolean variable like this:
Output:
It seems like when I ran the python script in the Jenkins config (not inside a file within my project) like how #souravatta suggested, it found the env variable. So that means the env variable Jenkins is setting, is on a different instance somehow (even though they are on the same computer, same user). I just did a workaround where I wrote the env variables to a file and then just read that file in my python script.
Trying to run the wordcount.py example from the data-flow quickstart example via pycharm, and I ran into an issue when parsing the command line arguments that contain environment variables.
When I set the environment variables and run the script in the terminal with the same paramaters it works just fine:
python wordcount.py --input gs://dataflow-samples/shakespeare/kinglear.txt --output gs://%BUCKET%/wordcount/outputs --runner DataflowRunner --project %PROJECT% --temp_location gs://%BUCKET%/tmp/
I tried the following variations of parsing the environment variables - none worked: ${ENV}, $ENV$, %ENV%.
I am working on Windows 10, PyCharm version 2019.3.1.
When you pass environment variables as values for the parameters (e.g., --project, --temp_location) to Pycharm configuration, it takes those variables as "string" values instead of their real values which you set on the first screenshot "User environment variables". I did a quick search for many related threads on StackOverflow but not find a solution so I came up with my own one, that is, using your current settings and replacing the values after parsing arguments in your code:
# Args parsing here
if args.project == "${PROJECT}":
args.project = os.environ.get("PROJECT")
args.temp_location = args.temp_location.replace("${BUCKET}", os.environ.get("BUCKET"))
However, I think you should consider using it when
you work with PyCharm more frequently than Terminal.
there are many arguments referring to environment variables and you have to change their values for different settings.
Hope Pycharm will support this feature soon.
Lately I have been doing some interactive work in Python.
My setup is an IPython notebook running on a server that uses a grid engine to manage jobs.
Today I was trying to get an IPython cluster going following an example posted here that uses subprocess.Popen to start a the cluster.
I couldn't get the example to work so I tried opening up the IPython/Jupyter terminal emulator and typing in the ipcluster start command and the cluster started right up!
After playing around with things for a while I realized that if I typed env in the terminal emulator I got a different list of environment variables than when I looked at the os.environ variable in Python. The source of the problem seemed to be that the PATH variables were different.
Now I know that I can change the PATH variable in os.environ, but I'm wondering why it is different in the first place? I know very little about environment variables, so this may be a stupid question, but I would have assumed that a terminal emulator and notebook running on the exact same node in the exact same IPython notebook server would have had the exact same environment variables.
Any insight on why the environment variables in the terminal and notebook might be different will be greatly appreciated.
Update: In case it matters, the server I am working on uses the Univa Grid Engine. Also I have noticed that it seems to make a difference whether I use qrsh or qsub to start the notebook server.
Previously I had been using qsub, but by starting the notebook server with qrsh I eliminate many of the differences between env and os.environ. There are still differences, but much fewer. Still not sure what any of that means though:)
As per manual page for qsub, qsh, qrsh, to propagate current shell environment to the job use the -V option:
-V Available for qsub, qsh, qrsh with command and qalter.
Specifies that all environment variables active within the qsub utility be exported to the context of the job.
All environment variables specified with -v, -V or the DISPLAY variable provided with -display will be exported to the defined JSV instances only optionally when this is
requested explicitly during the job submission verification. (see -jsv option above or find more information concerning JSV in jsv(1))