spaCy and spaCy models in setup.py











up vote
4
down vote

favorite












In my project I have spaCy as a dependency in my setup.py, but I want to add also a default model.



My attempt so far has been:



install_requires=['spacy', 'en_core_web_sm'],
dependency_links=['https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm'],


inside my setup.py, but both a regular pip install of my package and a pip install --process-dependency-links return:



pip._internal.exceptions.DistributionNotFound: No matching distribution found for en_core_web_sm (from mypackage==0.1)


I found this github issue from AllenAI with the same problem and no solution.



Note that if I pip install the url of the model directly, it works fine, but I want to install it as a dependency when my package is install with pip install.










share|improve this question




























    up vote
    4
    down vote

    favorite












    In my project I have spaCy as a dependency in my setup.py, but I want to add also a default model.



    My attempt so far has been:



    install_requires=['spacy', 'en_core_web_sm'],
    dependency_links=['https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm'],


    inside my setup.py, but both a regular pip install of my package and a pip install --process-dependency-links return:



    pip._internal.exceptions.DistributionNotFound: No matching distribution found for en_core_web_sm (from mypackage==0.1)


    I found this github issue from AllenAI with the same problem and no solution.



    Note that if I pip install the url of the model directly, it works fine, but I want to install it as a dependency when my package is install with pip install.










    share|improve this question


























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      In my project I have spaCy as a dependency in my setup.py, but I want to add also a default model.



      My attempt so far has been:



      install_requires=['spacy', 'en_core_web_sm'],
      dependency_links=['https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm'],


      inside my setup.py, but both a regular pip install of my package and a pip install --process-dependency-links return:



      pip._internal.exceptions.DistributionNotFound: No matching distribution found for en_core_web_sm (from mypackage==0.1)


      I found this github issue from AllenAI with the same problem and no solution.



      Note that if I pip install the url of the model directly, it works fine, but I want to install it as a dependency when my package is install with pip install.










      share|improve this question















      In my project I have spaCy as a dependency in my setup.py, but I want to add also a default model.



      My attempt so far has been:



      install_requires=['spacy', 'en_core_web_sm'],
      dependency_links=['https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm'],


      inside my setup.py, but both a regular pip install of my package and a pip install --process-dependency-links return:



      pip._internal.exceptions.DistributionNotFound: No matching distribution found for en_core_web_sm (from mypackage==0.1)


      I found this github issue from AllenAI with the same problem and no solution.



      Note that if I pip install the url of the model directly, it works fine, but I want to install it as a dependency when my package is install with pip install.







      python setup.py spacy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 21:12

























      asked Nov 19 at 22:09









      w4nderlust

      6421920




      6421920
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You can use pip's recent support for PEP 508 URL requirements:



          install_requires=[
          'spacy',
          'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
          ],


          Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.



          More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:




          As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.







          share|improve this answer





















          • Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
            – w4nderlust
            Nov 21 at 22:08












          • @w4nderlust: That sounds like a good idea to me.
            – jwodder
            Nov 21 at 22:10


















          up vote
          0
          down vote













          Not sure if this works for you, but in setup.py you might try:



          os.system('python -m spacy download en')



          after calling setuptools.setup(...)



          edit:



          According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:



          import en_core_web_sm
          nlp = en_core_web_sm.load()


          Ref: https://spacy.io/usage/models






          share|improve this answer























          • I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
            – w4nderlust
            Nov 21 at 22:02












          • Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
            – Wes Doyle
            Nov 21 at 22:14






          • 1




            Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
            – w4nderlust
            Nov 23 at 21:16











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383352%2fspacy-and-spacy-models-in-setup-py%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          You can use pip's recent support for PEP 508 URL requirements:



          install_requires=[
          'spacy',
          'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
          ],


          Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.



          More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:




          As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.







          share|improve this answer





















          • Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
            – w4nderlust
            Nov 21 at 22:08












          • @w4nderlust: That sounds like a good idea to me.
            – jwodder
            Nov 21 at 22:10















          up vote
          2
          down vote



          accepted










          You can use pip's recent support for PEP 508 URL requirements:



          install_requires=[
          'spacy',
          'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
          ],


          Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.



          More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:




          As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.







          share|improve this answer





















          • Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
            – w4nderlust
            Nov 21 at 22:08












          • @w4nderlust: That sounds like a good idea to me.
            – jwodder
            Nov 21 at 22:10













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          You can use pip's recent support for PEP 508 URL requirements:



          install_requires=[
          'spacy',
          'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
          ],


          Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.



          More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:




          As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.







          share|improve this answer












          You can use pip's recent support for PEP 508 URL requirements:



          install_requires=[
          'spacy',
          'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
          ],


          Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.



          More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:




          As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 22:42









          jwodder

          32.4k34879




          32.4k34879












          • Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
            – w4nderlust
            Nov 21 at 22:08












          • @w4nderlust: That sounds like a good idea to me.
            – jwodder
            Nov 21 at 22:10


















          • Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
            – w4nderlust
            Nov 21 at 22:08












          • @w4nderlust: That sounds like a good idea to me.
            – jwodder
            Nov 21 at 22:10
















          Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
          – w4nderlust
          Nov 21 at 22:08






          Thank you for your answer. I tested it and it actually works fine. I will not adopt it anyway, because I plan to to release the package on PyPI, but will mark as correct anyway. What do you suggest to do for a PyPI package? I was thinking about catching spaCy's FileNotFoundError and printing an error messages that suggests to run python -m spacy download en, would that be a good compromise?
          – w4nderlust
          Nov 21 at 22:08














          @w4nderlust: That sounds like a good idea to me.
          – jwodder
          Nov 21 at 22:10




          @w4nderlust: That sounds like a good idea to me.
          – jwodder
          Nov 21 at 22:10












          up vote
          0
          down vote













          Not sure if this works for you, but in setup.py you might try:



          os.system('python -m spacy download en')



          after calling setuptools.setup(...)



          edit:



          According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:



          import en_core_web_sm
          nlp = en_core_web_sm.load()


          Ref: https://spacy.io/usage/models






          share|improve this answer























          • I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
            – w4nderlust
            Nov 21 at 22:02












          • Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
            – Wes Doyle
            Nov 21 at 22:14






          • 1




            Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
            – w4nderlust
            Nov 23 at 21:16















          up vote
          0
          down vote













          Not sure if this works for you, but in setup.py you might try:



          os.system('python -m spacy download en')



          after calling setuptools.setup(...)



          edit:



          According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:



          import en_core_web_sm
          nlp = en_core_web_sm.load()


          Ref: https://spacy.io/usage/models






          share|improve this answer























          • I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
            – w4nderlust
            Nov 21 at 22:02












          • Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
            – Wes Doyle
            Nov 21 at 22:14






          • 1




            Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
            – w4nderlust
            Nov 23 at 21:16













          up vote
          0
          down vote










          up vote
          0
          down vote









          Not sure if this works for you, but in setup.py you might try:



          os.system('python -m spacy download en')



          after calling setuptools.setup(...)



          edit:



          According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:



          import en_core_web_sm
          nlp = en_core_web_sm.load()


          Ref: https://spacy.io/usage/models






          share|improve this answer














          Not sure if this works for you, but in setup.py you might try:



          os.system('python -m spacy download en')



          after calling setuptools.setup(...)



          edit:



          According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:



          import en_core_web_sm
          nlp = en_core_web_sm.load()


          Ref: https://spacy.io/usage/models







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 22:14

























          answered Nov 19 at 22:22









          Wes Doyle

          6051619




          6051619












          • I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
            – w4nderlust
            Nov 21 at 22:02












          • Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
            – Wes Doyle
            Nov 21 at 22:14






          • 1




            Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
            – w4nderlust
            Nov 23 at 21:16


















          • I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
            – w4nderlust
            Nov 21 at 22:02












          • Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
            – Wes Doyle
            Nov 21 at 22:14






          • 1




            Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
            – w4nderlust
            Nov 23 at 21:16
















          I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
          – w4nderlust
          Nov 21 at 22:02






          I tried it but it doesn't seem to work. I removed mypackage and spaCy from my local environment with pip uninstall, then installed mypackage again with pip install, it installed mypackage and spaCy, but then from the python interpreter import spacy works fine, while spacy.load('en') doesn't: FileNotFoundError: [Errno 2] No such file or directory: '/home/piero/dev/venv3/local/lib/python3.6/site-packages/spacy/data/en/__init__.py'. so I guess pip didn't run the additional line in the setup.py.
          – w4nderlust
          Nov 21 at 22:02














          Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
          – Wes Doyle
          Nov 21 at 22:14




          Not sure if you've seen this discussion, but it may be of some help: github.com/explosion/spaCy/issues/2676
          – Wes Doyle
          Nov 21 at 22:14




          1




          1




          Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
          – w4nderlust
          Nov 23 at 21:16




          Thank you for the additional comment and the edit Wes. I actually already install the model through pip rather than the usual python -m spacy download en, but it doesn't work in setup.py directly, you need to do it in the way @jwodder described that unfortunately doesn't work with PyPI.
          – w4nderlust
          Nov 23 at 21:16


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383352%2fspacy-and-spacy-models-in-setup-py%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'