I'm trying to run a scrapy project on a ubuntu server. For which I need to add the project path to python path.

I created a .bash_profile file in the /home directory with the following contents:


But I'm getting error running my python file stating it didn't find the module.

ImportError: No module named myscraper.items

I tried using the following paths, but nothing works.

  • /home/john/Desktop/myscraper/
  • /home/john/Desktop/myscraper
  • home/john/Desktop/myscraper/
  • home/john/Desktop/myscraper
  • 2
    Did you really create it in the /home directory - or in your $HOME directory? Did you really write EXPORT - or export? – steeldriver Feb 1 '18 at 23:42
  • I wrote EXPORT all in caps, and created the file in the /home directory. I don't know what you mean by the $HOME directory. – Raven Feb 1 '18 at 23:46

Config files belong in your personal home directory (/home/$USER, $HOME or simply ~), not in the /home directory. In your case that will be /home/john.

Please also make sure to use the correct casing, it's export in all lowercase.

Since export is not accessing but referencing the variable, you do not use the $ sign: export PYTHONPATH

Are you sure you want to have this in your .bash_profile and not your .bashrc? You can read up on the difference here.

In any case you will have to run source ~./bash_profile (or source ~./bashrc if you go with that) for your changes to take effect.

  • Just saw the comments by @steeldriver on the question. Sorry for posting duplicate content, credit of first posting this goes to him :) – NeoTheThird Feb 1 '18 at 23:52
  • 1
    It's all good - you might want to point out that the OP will need to log out and back in (or at least start a new login shell or source the ~/.bash_profile) for the change to take effect – steeldriver Feb 1 '18 at 23:55
  • It says `bash: export: /home/john/Desktop/myscraper:/home/john/Desktop/myscraper not a valid identifier' – Raven Feb 2 '18 at 0:04
  • 1
    Loose the $ after the export command and you should be fine: export PYTHONPATH You might want to request for that to be changed in the documentation that you're copying these commands from. – NeoTheThird Feb 2 '18 at 0:09
  • 1
    Run echo $PYTHONPATH to confirm the path has been added correctly. The output should contain /home/john/Desktop/myscraper. Debugging the software you're installing goes beyond the scope of this thread. – NeoTheThird Feb 2 '18 at 0:22

In addition to NeoTheThird's answer:

Ubuntu does not use ~/.bash_profile by default. You should use ~/.profile instead.

The path you should use is /home/john/Desktop/myscraper, though /home/john/Desktop/myscraper/ would also work. Paths that don't start with slashes are relative, not absolute, so will not work unless the working directory is /. More details here on Wikipedia.

You can put the definition and export statements together, and if PYTHONPATH is not already defined, you can leave off the $PYTHONPATH: at the start.

export PYTHONPATH=/home/john/Desktop/myscraper
  • +1 The hint on the relative path is good, forgot that in my answer. – NeoTheThird Feb 2 '18 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.