passenger_wsgi.py on dreamhost to get pylons working - pylons

This is what I found that in theory should work from git hub.com passenger-pylons-wsgi-example
import os, sys
sys.path.append('/home/user/test.sample.com/Helloworld')
os.environ['PYTHON_EGG_CACHE'] = '/home/user/tmp'
from paste.deploy import loadapp
def application(environ, start_response):
environ['SCRIPT_NAME'] = environ['PATH_INFO']
application = loadapp('config:/home/user/test.sample.com/production.ini')
return application(environ, start_response)
Tried it on dreamhost and I get:
An error occurred importing your
passenger_wsgi.py
I also tried the virtual environment but it didn't seem to work either.
mind you after following the instructions I have python 2.6 but no activate in the virtual directory.
Any ideas?
I also tried adding:
from fcgi import WSGIServer
and after the def application:
server = WSGIServer(application)
server.run()
But still get the same error. I wish it was a bit more descriptive so I could debug the passenger_wsgi

Finally found my answer:
import os, sys
INTERP = "/home/user/local/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.append('/home/user/test.sample.com/Helloworld')
os.environ['PYTHON_EGG_CACHE'] = '/home/user/tmp'
from paste.deploy import loadapp
def application(environ, start_response):
environ['SCRIPT_NAME'] = environ['PATH_INFO']
application = loadapp('config:/home/denat/test.sample.com/production.ini')
return application(environ, start_response)
The difference here is that the virtual environment was setup with pylons but wasn't using it. From the wiki on dreamhost I needed to add the following lines:
INTERP = "/home/user/local/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
I now have a working pylons app! Yay!
I know others have been looking for this so I hope this helps them.

Related

Getting error when adding package to Spacy pipe

I'm getting an error while adding a spacy compatible extension, med7, to the pipeline. I've included the replicable code below.
!pip install -U https://med7.s3.eu-west-2.amazonaws.com/en_core_med7_lg.tar.gz
import spacy
import en_core_med7_lg
from spacy.lang.en import English
med7 = en_core_med7_lg.load()
# Create the nlp object
nlp2 = English()
nlp2.add_pipe(med7)
# Process a text
doc = nlp2("This is a sentence.")
The error I get is
Argument 'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)
I realized I was having this problem because I don't understand the difference some components of Spacy. For instance, in the Negex extension package, loading the pipeline is done with the Negex command:
negex = Negex(nlp, ent_types=["PERSON","ORG"])
nlp.add_pipe(negex, last=True)
I don't understand what the difference between Negex and en_core_med7_lg.load(). For some reason, I when add "med7" into the pipeline, it causes this error. I'm new to Spacy and would appreciate an explanation so that I can learn. And please let me know if I can make this question any more clear. Thanks!
med7 is already the loaded pipeline. Run:
doc = med7("This is a sentence.")

Not able to save pyspark iforest model using pyspark

Using iforest as described here: https://github.com/titicaca/spark-iforest
But model.save() is throwing exception:
Exception:
scala.NotImplementedError: The default jsonEncode only supports string, vector and matrix. org.apache.spark.ml.param.Param must override jsonEncode for java.lang.Double.
Followed the code snippet mentioned under "Python API" section on mentioned git page.
from pyspark.ml.feature import VectorAssembler
import os
import tempfile
from pyspark_iforest.ml.iforest import *
col_1:integer
col_2:integer
col_3:integer
assembler = VectorAssembler(inputCols=in_cols, outputCol="features")
featurized = assembler.transform(df)
iforest = IForest(contamination=0.5, maxDepth=2)
model=iforest.fit(df)
model.save("model_path")
model.save() should be able to save model files.
Below is the output dataframe I'm getting after executing model.transform(df):
col_1:integer
col_2:integer
col_3:integer
features:udt
anomalyScore:double
prediction:double
I have just fixed this issue. It was caused by an incorrect param type. You can checkout the latest codes in the master branch, and try it again.

socketIO-client-nexus 0.7.6 - StopIteration error

from socketIO_client_nexus import SocketIO, LoggingNamespace
from requests.exceptions import ConnectionError
try:
socket = SocketIO('https://myURL/myendpoint', verify=False, wait_for_connection=False)
socket.wait()
except ConnectionError:
print('The server is down. Try again later.')
When I run the above code, I get the below stack trace.
This is a quite known issue. People who faced this issue said that it happened because the socket server that they were trying to connect to was built on socketio 2.x.
However, socketIO-client-nexus 0.7.6 seems to have reportedly solved their problems.
However, I'm still facing the same issue. Don't know what's wrong.
The server that I'm trying to connect to is built on socketio 2.0.1
Finally got it working. Reference https://pypi.org/project/socketIO-client-nexus/
Here's the working code.
from socketIO_client_nexus import SocketIO, BaseNamespace
class ChatNamespace(BaseNamespace):
def custom_response(self, *args):
print('on_custom_response', args)
socketIO = SocketIO('https://myIP', verify=False)
chat_namespace = socketIO.define(ChatNamespace, '/mynamespace')
socketIO.wait()

Error running ParseTree

In the Rascal shell, doing this:
import lang::c90::\syntax::C;
import ParseTree;
parse(#TranslationUnit, |file:///teste.c|);
I get in the stable standalone jar:
|prompt:///|(24,93,<1,24>,<1,117>): ParseError(|file:///home/rafael2k/files/UnB/static_analysis/eclipse-workspace/rascal-C/c-source/teste.c|(47,0,<4,0>,<4,0>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
at *** somewhere ***(|prompt:///|(24,93,<1,24>,<1,117>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
And in Eclipse I get a giant message error:
(...)
public AbstractStackNode<IConstructor>[] FloatingPointConstant() {
return FloatingPointConstant.EXPECTS;
}
public AbstractStackNode<IConstructor>[] StructDeclarator() {
return StructDeclarator.EXPECTS;
}
}
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaCompilation/JavaCompilation.html|null
Any tip?
Btw, running Debian Jessie, Oracle Java 1.8.0_112,x86_64.
I think it can be fixed with this:
parse(#start[TranslationUnit], |file:///teste.c|);
By using a start non-terminal you can parse files which begin and/or end with whitespace or source code comments. See also the answer to this question: Layout in Rascal
By the way, this grammar will parse c programs after the processor has been applied.
The Eclipse error is a seemingly unrelated issue for which we would love to receive a stack trace on the github issue tracker.

javac will not compile enum, ( Windows Sun 1.6 --> OpenJDK 1.6)

package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)

Resources