yoeo / guesslang

Detect the programming language of a source code
https://guesslang.readthedocs.io
MIT License
773 stars 110 forks source link

ModuleNotFoundError: No module named 'guesslang' #34

Closed bhuvi11 closed 2 years ago

bhuvi11 commented 2 years ago

Hello Team,

I have installed Tensorflow and guesslang

C:\Users\bhuvaneshwari>pip3 show tensorflow Name: tensorflow Version: 2.5.0 Summary: TensorFlow is an open source machine learning framework for everyone. Home-page: https://www.tensorflow.org/ Author: Google Inc. Author-email: packages@tensorflow.org License: Apache 2.0 Location: c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages Requires: keras-preprocessing, termcolor, flatbuffers, tensorboard, gast, tensorflow-estimator, google-pasta, numpy, wheel, six, wrapt, keras-nightly, absl-py, typing-extensions, astunparse, protobuf, h5py, opt-einsum, grpcio Required-by: guesslang

C:\Users\bhuvaneshwari>pip3 show tensorflow Name: tensorflow Version: 2.5.0 Summary: TensorFlow is an open source machine learning framework for everyone. Home-page: https://www.tensorflow.org/ Author: Google Inc. Author-email: packages@tensorflow.org License: Apache 2.0 Location: c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages Requires: keras-preprocessing, termcolor, flatbuffers, tensorboard, gast, tensorflow-estimator, google-pasta, numpy, wheel, six, wrapt, keras-nightly, absl-py, typing-extensions, astunparse, protobuf, h5py, opt-einsum, grpcio Required-by: guesslang

When i try guesslang as a CLI , i get 'guesslang' is not recognized as an internal or external command,

When i try as a package in python program i get ModuleNotFoundError: No module named 'guesslang'

Thanks in advance

yoeo commented 2 years ago

Hi @bhuvi11,

It looks like were an issue during Guesslang installation. Could you force-install it with pip3 install -U guesslang then share the console output?

bhuvi11 commented 2 years ago

Hello Yoeo, I tried with the above command and got this: C:\Users\bhuvaneshwari>pip3 install -U guesslang Collecting guesslang Using cached guesslang-2.0.3-py3-none-any.whl (2.1 MB) Requirement already satisfied: tensorflow==2.5.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from guesslang) (2.5.0) Requirement already satisfied: flatbuffers~=1.12.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.12) Requirement already satisfied: absl-py~=0.10 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (0.13.0) Requirement already satisfied: tensorboard~=2.5 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (2.5.0) Requirement already satisfied: opt-einsum~=3.3.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (3.3.0) Requirement already satisfied: keras-preprocessing~=1.1.2 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.1.2) Requirement already satisfied: astunparse~=1.6.3 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.6.3) Requirement already satisfied: keras-nightly~=2.5.0.dev in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (2.5.0.dev2021032900) Requirement already satisfied: typing-extensions~=3.7.4 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (3.7.4.3) Requirement already satisfied: google-pasta~=0.2 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (0.2.0) Requirement already satisfied: wrapt~=1.12.1 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.12.1) Requirement already satisfied: wheel~=0.35 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (0.36.2) Requirement already satisfied: protobuf>=3.9.2 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (3.17.3) Requirement already satisfied: grpcio~=1.34.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.34.1) Requirement already satisfied: six~=1.15.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.15.0) Requirement already satisfied: gast==0.4.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (0.4.0) Requirement already satisfied: tensorflow-estimator<2.6.0,>=2.5.0rc0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (2.5.0) Requirement already satisfied: termcolor~=1.1.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.1.0) Requirement already satisfied: h5py~=3.1.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (3.1.0) Requirement already satisfied: numpy~=1.19.2 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorflow==2.5.0->guesslang) (1.19.5) Requirement already satisfied: requests<3,>=2.21.0 in c:\users\bhuvaneshwari\appdata\roaming\python\python39\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (2.23.0) Requirement already satisfied: markdown>=2.6.8 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (3.3.4) Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (0.4.4) Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (1.8.0) Requirement already satisfied: werkzeug>=0.11.15 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (2.0.1) Requirement already satisfied: setuptools>=41.0.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (56.0.0) Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (0.6.1) Requirement already satisfied: google-auth<2,>=1.6.3 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from tensorboard~=2.5->tensorflow==2.5.0->guesslang) (1.33.0) Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (0.2.8) Requirement already satisfied: rsa<5,>=3.1.4 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (4.7.2) Requirement already satisfied: cachetools<5.0,>=2.0.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (4.2.2) Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (1.3.0) Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (0.4.8) Requirement already satisfied: idna<3,>=2.5 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (2.10) Requirement already satisfied: certifi>=2017.4.17 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (2021.5.30) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\bhuvaneshwari\appdata\roaming\python\python39\site-packages (from requests<3,>=2.21.0->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (1.25.9) Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (3.0.4) Requirement already satisfied: oauthlib>=3.0.0 in c:\users\bhuvaneshwari\appdata\local\programs\python\python39\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.5->tensorflow==2.5.0->guesslang) (3.1.1) Installing collected packages: guesslang Successfully installed guesslang-2.0.3

After this i tried guesslang CLI , getting the same error

In Sypder i get " ImportError: cannot import name 'Guess' from 'guesslang' (unknown location)"

Can you help me on this please ?

yoeo commented 2 years ago

Okay I see, it looks like Spyder IDE uses its own Python environment. So even if you install Guesslang on your default Python environment, Spyder won't see it.

According to Spyder's documentation, you can either install the package inside Spyder, or tell Spyder where to look for the missing packages:

I hope it helps.

bhuvi11 commented 2 years ago

Hello Yoeo, Thanks let me try with the python settings in spyder.

But even the guesslang CLI is not working, I gave pip3 install guesslang, It got installed successfully.

Then i C:\Users\bhuvaneshwari\Downloads>guesslang 'guesslang' is not recognized as an internal or external command, operable program or batch file.

Am i missing anything???

Note: Python version 3.9

yoeo commented 2 years ago

Hi @bhuvi11,

Indeed the CLI can currently not run on vanilla Windows. That should not be related to the issues on Spyder.

In fact the CLI script is written for an UNIX shell https://github.com/yoeo/guesslang/blob/cbc441d6a3c5512217b503844cb4cd62b3664e39/bin/guesslang#L1 It will work well on BSD, Linux, Mac OS and also on Windows if you use the subsystem for Linux https://docs.microsoft.com/en-us/windows/wsl/about

One simple workaround is to run Guesslang CLI through Python. Example:

C:\Path\To\Python\python.exe -m guesslang --help
yoeo commented 2 years ago

I don't have a Windows device to test the CLI script. But if you can help me test it I'll gladly work on a multiplatform CLI script that could work vanilla Windows (i.e: Windows without the subsystem for Linux).

bhuvi11 commented 2 years ago

I will definitely help with the testing.

I just tried the option using C:\Users\bhuvaneshwari\AppData\Local\Programs\Python\Python39>python.exe -m guesslang --help. Let me see if this works

yoeo commented 2 years ago

@bhuvi11, cool.

I prepared a new version that should (hopefully) work on Windows https://github.com/yoeo/guesslang/pull/36

Step to test it:

# Uninstall any existing Guesslang package
pip uninstall -y guesslang

# Install the new version
pip install git+https://github.com/yoeo/guesslang/@v2.2.1

# Test the new version
guesslang /path/to/source_code_file

Please let me know if you have any issue.

bhuvi11 commented 2 years ago

Hello Yoeo,

I tried it and got the below permission denied issue C:\Windows\system32>guesslang -d C:\Users\bhuvaneshwari\eclipse-workspace\ecom-service usage: guesslang [-h] [-p] [-l] [--train TRAINING_DIRECTORY] [--steps TRAINING_STEPS] [--model MODEL_DIR] [-d] [filename] guesslang: error: argument filename: can't open 'C:\Users\bhuvaneshwari\eclipse-workspace\ecom-service': [Errno 13] Permission denied: 'C:\Users\bhuvaneshwari\eclipse-workspace\ecom-service'

yoeo commented 2 years ago

OK so the installation didn't fail and the command line tool is now compatible with Windows CLI.

I tried it and got the below permission denied issue I have pretty similar errors on Linux when I run Guesslang with a directory instead of a file.

$ guesslang code/
usage: guesslang [-h] [-p] [-l] [--train TRAINING_DIRECTORY] [--steps TRAINING_STEPS] [--model MODEL_DIR] [-d] [filename]
guesslang: error: argument filename: can't open 'code/': [Errno 21] Is a directory: 'code/'

Is ecom-service is a directory?

bhuvi11 commented 2 years ago

Hello Yoeo, Yeah ecom-service is the directory. I am wondering why i am getting permission denied issue?

yoeo commented 2 years ago

Maybe Windows treats different file system access issues as permission issues. I'm just making a wild assumption, I have no idea of what the actual reason is :-)

I'll merge the "windows-compatible" pull request then.

And thanks for your help :+1:

bhuvi11 commented 2 years ago

Hello Yoeo, Sure . Thanks for your help

yoeo commented 2 years ago

All the changes are now deployed :-)