-2

I was trying to add the Strings library into the Robot Framework Interpreter folder in PyCharm, where first it showed me error

Command errored out with exit status: 1

So, I googled out this issue first, and this link suggested me to delete 'strings.py' file from the libraries. I did so and now nothing is working. Anything I do now, it shows error of "ModuleNotFoundError: No module named 'string'".

I could not even install string using

pip install strings

command. Whatever I try to do with pip, now shows this error.

Can anyone please suggest me the solution for this? I am using Python version 3.10.

wovano
  • 4,543
  • 5
  • 22
  • 49
JayyM
  • 155
  • 1
  • 3
  • 13
  • Are you sure it is `strings` and not `string`? – Anand Gautam Jan 28 '22 at 06:50
  • @AnandGautam I am sure the library has Strings, but the error shows String – JayyM Jan 28 '22 at 06:53
  • The error you see now shows `string` because that's the file you deleted, so now you don't have access to it. The library showed a different error, which says `strings`, *during the attempt to install*. It did not actually install. If you are sure that you see an error that says `string`, without an `s`, when you run pip, then that just means `pip` needs the standard library `string` to do its work, too. – Karl Knechtel Jan 28 '22 at 08:12
  • 1
    I don't understand why you wanted to install this library in the first place. – Karl Knechtel Jan 28 '22 at 08:13
  • I actually need this library to automate my project through Robot Framework. – JayyM Jan 28 '22 at 09:15
  • 1
    @JayyM please be aware that the String library from Robotframework (https://robotframework.org/robotframework/latest/libraries/String.html) is a completely different thing and comes bundled with the usual Robotframework installation. Is this the library that you want to use? – hfc Jan 28 '22 at 09:42
  • can you try to install the desired packages with conda or pip using the terminal? Show the error message so we can help. – DanielTuzes Jan 28 '22 at 19:41
  • Could you [edit] your post and be more specific about what library you need: `Strings`, `strings` or `string`. You mentioned all three in your question, but these are (at least) three different libraries. Preferably, add a link to the library you mean. Also, be more specific about the file you deleted "_from the libraries_". What is the path of the file you deleted? Also include (copy-paste) the exact error messages you got when a command failed. – wovano Jan 29 '22 at 09:18

4 Answers4

1

Several notes:

  1. The library in question is 9 years old, is not maintained, is known by the author to be buggy, was written as a joke, and does not contain anything useful. There is no good reason why you should be trying to install it for your project. If you think you need it for something, then you have some other misconception that needs to be cleared up.

  2. The link you found did not tell you to delete strings.py from "the libraries". It said something about deleting string.py - notice, no s at the end - from a local project folder. The reason for this is because that name conflicts with the library name. The page author's own source file, named string.py, sought to import the standard library file string.py (as it clearly says import string in the screen shot), but it cannot - because it finds itself first. This is a common problem for new Python users.

DO NOT EVER MANUALLY EDIT THE CONTENTS OF YOUR INSTALLATION DIRECTORY ON THE ADVICE OF SOME RANDOM WEB PAGE.

Ideally, don't ever do it at all. That content is not intended to be touched. Installers exist for a reason. If for some incredibly specific reason you feel the need to do this, make sure you have backups of everything and that you are 100% sure you can restore everything to its initial state if anything goes wrong.

  1. The person writing that web page was incorrect. The installation error had nothing to do with the string.py file.

  2. The actual cause of the problem is that the package is broken and cannot be installed properly on anyone else's machine. Again, this is no big loss as there is no use for the package anyway.

The reason it is broken is that the setup script for the package tries to import the code that's being installed, in order to get version and author information. This seems to work locally, but fails for everyone else.

  1. To reiterate: the person writing that article wrote nonsense. (I'm not surprised; the page formatting is awful and the grammar isn't particularly great either.) Looking further, it appears that the entire website is authored by the one person, who is clearly just trying to self-promote (with a Youtube channel as well) while lacking the necessary expertise. Browsing around the rest of the site a bit, I see articles that are pedantic and not very insightful, and occasionally inaccurate - but all very SEO optimized.

I recommend ignoring that website entirely.

  1. To reiterate: the string module comes with your Python. You cannot reinstall it with pip - not with the strings package you found, nor any other package. Your options are:

    • Find the correct string.py contents (possibly from a backup, assuming you thought to make a backup before deleting something from an installation directory) and restore them. This is the official repository for the reference implementation of Python. You might be able to find it in there somewhere. I don't recommend trying. There is a lot to go through and it is possible to damage things further.

    • Reinstall Python completely.

wovano
  • 4,543
  • 5
  • 22
  • 49
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Looking into it a little more, it appears that the relevant code *doesn't even make it into the download* - only the setup script and other metadata are included. – Karl Knechtel Jan 28 '22 at 08:38
0

The error that you are getting is because you deleted the string.py file. There is no string module to be imported from PyPi. This is why pip install string doesn't work. Restore the deleted file as it is not the cause of your problem.

If you try to install Strings library it will fail because you are using Python 3.10 and the Strings library that you want to import and install is quite old and not supported for this Python version. Therefore you get the ModuleNotFoundError: No module named 'strings' that you see in the link that you attached.

For the setup.py file from the library I see that it recommends using Python 3.3, so I will recommend you to use that version of Python if you want to use this specific library.

Please note that the link that you provided is probably in case that you have created your own string.py file.

hfc
  • 614
  • 1
  • 5
  • 13
  • 1
    This will not resolve the problem, and misunderstands the issue with the installation. The message did not say `No module named 'string'` *during the installation*. It said `No module named 'strings'`, with an `s`. This is because the installer wants to `import` its own content, which does not work for new installs - but would have appeared to work for the developer. Also, a local file in a project directory is definitely not the cause of an **installation** problem. That linked web page is simply incorrect. – Karl Knechtel Jan 28 '22 at 08:10
  • 1
    "_The error is probably caused..._" This is just guessing. And wrong guessing too. `string` is still a standard library in Python 3.10 so it shouldn't give that error message. See https://docs.python.org/3.10/library/string.html Also note that `string` and `strings` (and `String` and `Strings`) are completely different things. – wovano Jan 28 '22 at 08:25
  • Please note that the error mentioned in the link is different than the error mentioned in the question. The link says `ModuleNotFoundError: No module named 'strings'` with `s`. Here the user says that the error is `ModuleNotFoundError: No module named 'string'` without `s`. Also note that the user mentions that the error is coming when `pip install strings` is executed. – hfc Jan 28 '22 at 09:27
-1

I solved this question by deleting any __pycache__ folder in the project directory.

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32366281) – Simas Joneliunas Aug 04 '22 at 00:27
-1

you have to write in terminal

pip install strings

and then you have to import strings library as string

import string

This error is just because of using strings

  • Did you read the question, comments and other answers thoroughly? And did you test your solution? `import string` just imports the Python Standard Library [string](https://docs.python.org/3/library/string.html) module, which is completely unrelated to the module you install using `pip`. Your explanation could be improved as well "_This error is just because of using strings_" doesn't explain the issue very well. – wovano Apr 01 '23 at 07:48