cd command in python - python

I am new to python and
I am trying to test syntaxnet in python using this github repo.
and in the section "how to run the parser" is as following :
git clone https://github.com/spoddutur/syntaxnet.git
cd <syntaxnet-git-clone-directory>
python main.py
That's it!! It prints syntaxnet dependency parser output for given input english sentence
through some research, I understood that first one indicates that I need to install the syntaxnet package in my cmd so I did and the package was successfully installed.
but I don't understand how to perform the second one
what does cd do, and where and how should I use it?
also in main.py,
from my_parser_eval import SyntaxNetProcess
from my_parser_eval import _write_input
from my_parser_eval import _read_output
from my_parser_eval import pretty_print
eclipse cannot find those imports, even after I created a package/module named my_parser_eval that includes all necessary codes from the reference

The CD command means Change Directory.
Once you have finished cloning Syntaxnet Github Repository, you should enter its directory. That's why you have to enter CD command.
But have in mind that CD takes one parameter - the directory you want to enter.
In order to solve your problem you must write cd syntaxnet resulting in:
git clone https://github.com/spoddutur/syntaxnet.git
cd syntaxnet
python main.py
First command:
Second command

Related

ta-lib replit python install problem, ERROR: No matching distribution found for talib-binary

I use it on my windows machine by downloading its binary. I also use it in Heroku from its herokus build pack. I don't know what operating system replit use. But I try every possible commed like.
!pip install ta-lib
!pip install talib-binary
It's not working with replit. I thought it work like google co-lab but its not the same.
can anyone use TA-LIB with replit. if so. How you install it?
Getting TA-Lib work on Replit
(by installing it from sources)
Create a new replit with Nix toolset with a Python template.
In main.py write:
import talib
print (talib.__ta_version__)
This will be our test case. If ta-lib is installed the python main.py (executed in Shell) will return something like:
$ python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
We need to prepare a tools for building TA-Lib sources. There is a replit.nix file in your project's root folder (in my case it was ~/BrownDutifulLinux). Every time you execute a command like cmake the Nix reports that:
cmake: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
cmake.out
cmakeCurses.out
cmakeWithGui.out
cmakeMinimal.out
cmake_2_8.out
If you select cmake.out it will add a record about it into the replit.nix file. And next time you call cmake, it will know which cmake version to launch. Perhaps you may manually edit replit.nix file... But if you're going to add such commands in a my way, note that you must execute them in Shell in your project root folder as replit.nix file is located in it. Otherwise Nix won't remember your choice.
After all my replit.nix file (you may see its content with cat replit.nix) content was:
{ pkgs }: {
deps = [
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
pkgs.python38Full
];
env = {
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
# Needed for pandas / numpy
pkgs.stdenv.cc.cc.lib
pkgs.zlib
# Needed for pygame
pkgs.glib
# Needed for matplotlib
pkgs.xorg.libX11
];
PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
LANG = "en_US.UTF-8";
};
}
Which means I executed libtool, autoconf, automake and cmake in Shell. I always choose a generic suggestion from Nix, without a specific version. Note: some commands may report errors as we executing them in a wrong way just to add to a replit.nix.
3.
Once build tools are set up we need to get and build TA-Lib C library sources. To do that execute in Shell:
git clone https://github.com/TA-Lib/ta-lib.git
then
cd ta-lib/
libtoolize
autoreconf --install
./configure
If configure script is completed without any problems, build the library with:
make -j4
It will end up with some compilation errors, but they are related to some additional tools which are used to add new TA-Lib indicators and build at the end, but not the library itself. The library will be successfully compiled and you should be able to see it with:
$ ls ./src/.libs/
libta_lib.a libta_lib.lai libta_lib.so.0
libta_lib.la libta_lib.so libta_lib.so.0.0.0
Now we have our C library built, but we can't install it to a system default folders. So we have to use the library as is from the folders where it was build. All we need is just one more additional preparation:
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
This will copy a library headers to a subfolder, as they are designed to be used from a such subfolder (which they don't have due to impossibility to perform the installation step).
4.
Now we have TA-Lib C library built and prepared to be used locally from its build folders. All we need after that - is to compile the Python wrapper for it. But Python wrapper will look for a library only in system default folders, so we need to instruct it where our library is.
To do this, execute pwd and remember the absolute path to your project's root folder. In my case it was:
/home/runner/FormalPleasedOffice
Then adjust the paths (there are two) in a following command to lead to your project path:
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
This is one line command, not a two commands.If the paths would be shorter it would look like:
TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib.
After execution of this command the wrapper will be installed with two additional paths where it will look for a library and its header files.
That's actually all.
An alternative way would be to clone the wrapper sources, edit its setup.py and install wrapper manually. Just for the record this would be:
cd ~/Your_project
git clone https://github.com/mrjbq7/ta-lib.git ta-lib-wrapper
cd ta-lib-wrapper
Here edit the setup.py. Find the lines include_dirs = [ and library_dirs = [ and append your paths to these lists. Then you just need to:
python setup.py build
pip install .
Note the dot at the end.
5.
Go to the project's folder and try our python script:
$python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
Bingo!
The #truf answer is correct.
after you add the
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
in the replit.nix dippendancies.
git clone https://github.com/TA-Lib/ta-lib.git
cd ta-lib/
libtoolize
autoreconf --install
./configure
make -j4
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
Note : FormalPleasedOffice should be your project name
Done.
Here is the youtube video :
https://www.youtube.com/watch?v=u20y-nUMo5I

Can't Add Ml backend in label-studio

I am trying to add my ML model on label studio.
I have tried these commands
cd label-studio
pip install -e .
cd label_studio/ml/examples
pip install -r requirements.txt
label-studio-ml init my_ml_backend --script label_studio/ml/examples/simple_text_classifier.py
These are the files in label_studio/ml/examples:-
requirements.txt
simple_text_classifier.py
dummy_model.py
pytorch_transfer_learning.py
It's giving me this error:
ModuleNotFoundError: No module named 'simple_text_classifier'
How can I add my model on label studio?
Probably a little late, but maybe someone else finds this question. What did the trick for me: while in the label_studio/ml/examples folder, try
label-studio-ml init my_ml_backend --script simple_text_classifier.py
(I simply removed the rest of the parth from the script)
If you get an error telling you to add --force, do either that (which will override the existing my_ml_backend folder) or simply delete the my_ml_backend folder and run the same command again.
After that, you hopefully should get the following response:
Congratulations! ML Backend has been successfully initialized in ./my_ml_backend
Now start it by using:
label-studio-ml start ./my_ml_backend
The quick solution that worked for me is that I navigated (cd) to the directory containing simple_text_classifier.py i.e. examples, and then from that directory executed the command:
label-studio-ml init my_ml_backend --script simple_text_classifier.py

Running a flask app that uses multiple conda environments

As the title says, I want to either run multiple conda environements from 1 flask app such that certain pages use 1 version of packages and the others use a different version of packages.
Alternatively, I could do something where I run 2 apps concurrently and then would need to be able to properly redirect from one to another.
I scoured the internet and didn't find anything. Any ideas/documentation on where to get started?
EDIT I was told this was a bad idea and to elaborate on the problem rather than my attempted solution
The problem is that I have certain packages that I am trying to interact with 2 different ML models that were done in different versions of scikit. I can't recreate the model because it was given to me by a coworker. Additionally I am doing some name matching using fuzzywuzzy which is causing issues with other packages I need.
You can do what you are asking by installing both versions to different locations (so they don't overwrite each other), and then renaming the package as this seems to be your only option.
Take the following example, I am going to setup 2 virtual environments, in the first I'll install scitkit-learn 0.22.2 and in the second I'll install 0.20.4, then move the name of the package so python can differentiate them and print the version ($ denotes something to enter on the command line):
$ python3 -m venv sk1
$ source sk1/bin/activate
$ pip3 install scikit-learn==0.22.2 # install to venv 1
$ deactivate # leave
$ python3 -m venv sk2
$ source sk2/bin/activate
$ pip3 install scikit-learn==0.20.4 # install to venv 2
$ deactivate
# move the package names
$ mv ./sk1/lib/python3.7/site-packages/sklearn ./sk1/lib/python3.7/site-packages/sklearn0222
$ mv ./sk2/lib/python3.7/site-packages/sklearn ./sk2/libpython3.7/site-packages/sklearn0204
# add both of them to your PYTHONPATH
$ export PYTHONPATH=$PYTHONPATH:$(pwd)/sk1/lib/python3.7/site-packages/sklearn0222
$ export PYTHONPATH=$PYTHONPATH:$(pwd)/sk2/lib/python3.7/site-packages/sklearn0204
Now let's go into the python interpreter, import them:
$ python3
>>> import sklearn0222 as sk0222
>>> import sklearn0204 as sk0204
>>> sk0222.__version__
'0.22.2'
>>> sk0204.__version__
'0.20.4'
This will use the packages version specific code to run, but you have to be SUPER CAREFUL when referencing each and you cannot use both packages within the same module. so in mymodule1.py you can import sklearn0222 and use its submodules and in mymodule2.py you can import sklearn0204 and use its submodules, but if you try to use both in the same module in your program the second will not be recognized.
Again, this is a bad idea but this is a way to get what you are looking for.

scons -u and variantdirs

I've been working with SCons for a while now and I'm facing a problem that I can't manage to resolve, I hope someone can help me. I created a dummy project that compiles a basic helloWorld (in main.cpp). What I want to do is compile my binary from 'test' folder using the scons -u command. All of my build is done in a variant dir that will eventually be created at the root of the project (build folder).
Here's my folder tree :
+sconsTest
-SConstruct
+ test
-SConscript
+test2
-SConscript
-main.cpp
+build (will eventually be created by scons)
Following is the SConstruct code:
env = Environment()
env.SConscript('test/SConscript', {'env' : env})
Following is test/SConscript code:
Import('env')
env = env.Clone()
env.SConscript('test2/SConscript', {'env' : env}, variant_dir="#/build", duplicate=0)
Following is test2/SConscript code:
Import('env')
env = env.Clone()
prog = env.Program('main', 'main.cpp')
After placing myself in 'sconsTest/test' folder, I type in scons -u, I expect it to build my program, however all it says is 'test' is up to date. When nothing is compiled. I noticed something, when I remove both variant_dir and duplicate args from test/SConscript, the scons -u works.
Furthermore, I noticed it was possible for me to compile the program using the command
scons -u test2
However, I'm using scons on a large scale project and I don't like giving a relative path as an argument to compile my project. I want scons -u to automatically build everything it finds in subdirs.
Do anyone have any idea on how to resolve this issue?
Please check the MAN page again. The -u option will only build default targets at or below the current directory. This excludes your folder sconsTest/build when you're in sconsTest/test.
What you are looking for is the -U option (with the capital "U") instead. It builds all default targets that are defined in the SConscript(s) in the current directory, regardless of what directory the resultant targets end up in.

add extra modules to opencv python?

I have a problem in python opencv!
I want to use SIFT algorithm which is not a default algorithm in opencv package. So I have to build OpenCV with extra modules as bellow:
You can build OpenCV, so it will include the modules from this repository. Here is the CMake command for you:
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
$ make install
I did all these steps and it was successfully build. But I'm getting error when I call sub modules of opencv (e.g. xfeatures2d, objdetect). I tried using following code;
$ import cv2
$ x = cv2.xfeatures2d()
It gives me error that "module' object has no attribute 'xfeatures2d'".
Do you have any ideas?
Download opencv_contrib from here
Download opencv from here
Now create a new directory called opencv_build
Now go to opencv_build directory
Here <opencv_contrib> points to downloaded folder from step 1
And <opencv_source_directory> points to downloaded folder from step 2
Substitute their paths in your cmake command.

Categories

Resources